[YANGTOOLS-1468] JsonParserStream cannot read augmentations Created: 22/Nov/22  Updated: 15/Mar/23  Resolved: 15/Mar/23

Status: Resolved
Project: yangtools
Component/s: codecs
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Medium
Reporter: Ivan Hrasko Assignee: Ruslan Kashapov
Resolution: Won't Do Votes: 0
Labels: pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Blocks
blocks NETCONF-911 JSON reader: Eliminate additional log... Confirmed

 Description   

JsonParserStream is not able to read augmented container data.

Here is the log:

java.lang.IllegalStateException: Schema node with name container-aug was not found under (test-ns-aug)container-aug.    at org.opendaylight.yangtools.yang.data.codec.gson/org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream.resolveNamespace(JsonParserStream.java:410)
    at org.opendaylight.yangtools.yang.data.codec.gson/org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream.read(JsonParserStream.java:308)
    at org.opendaylight.yangtools.yang.data.codec.gson/org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream.parse(JsonParserStream.java:193)
    at org.opendaylight.yangtools.yang.data.codec.gson/org.opendaylight.yangtools.yang.data.codec.gson.YT1468JsonTest.fromJSON(YT1468JsonTest.java:70)
    at org.opendaylight.yangtools.yang.data.codec.gson/org.opendaylight.yangtools.yang.data.codec.gson.YT1468JsonTest.testReadAugmentedContainer(YT1468JsonTest.java:59)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) 

Please see a reproducer in https://git.opendaylight.org/gerrit/c/yangtools/+/103307.



 Comments   
Comment by Ruslan Kashapov [ 03/Feb/23 ]

there is no issues parsing augmented nodes, see https://git.opendaylight.org/gerrit/c/yangtools/+/104237

so called parentNode parameter used to define non-root element to parse has a different meanings for XML and JSON parsers

  • in XML parser parentNode points to root xml element, so returned node identifier matches it exactly the one of parentNode
  • in JSON parser parentNode indicates parsing context (belongings of top level parenthesis), and returned node is a recognized direct child of parentNode

this difference is historical and assumes significant code base which relies on behavior explained above

for augmentation case the augmentation itself became a standalone (structural, non-data) node within hierarchy of parsed node structure:
container-root > container-lvl1 > augmentation > container-aug > leaf-aug

according to behavior explained above same

parentNode -> container-aug means (to parse and return) container-aug for XML parser and leaf-aug for JSON parser
parentNode -> container-lvl1 means container-lvl1 for XML parser and augmentation node for JSON parser 

due to parentNode cannot be pointed to augmentation node JSON parser cannot return container-aug as direct child

due to JSON parser cannot define exact node to parse, it's not reasonable to expect exact node to be returned by parser.

 

next action (to confirm)

  • close as not a bug
  • normalize behavior: same meaning of parentNode for both parsers (significant effort and impact expected)
  • add a workaround to never return augmentation node as top level node on parsing (seems unjustified)
Comment by Ivan Hrasko [ 03/Feb/23 ]

Original tests in https://git.opendaylight.org/gerrit/c/yangtools/+/103307 contain additional check that the returned data is a container.

  • Even if you use parent node as parameter in JSON you read augmentation - but we would like to get container.
  • Different node/parent node parameters should be documented.
Comment by Ivan Hrasko [ 03/Feb/23 ]

In addition, it looks like a new bug is there - we cannot read leaf value from XML: https://git.opendaylight.org/gerrit/c/yangtools/+/104237/1..2

Comment by Ivan Hrasko [ 15/Mar/23 ]

The problems will be addressed in YANGTOOLS-1415.

Generated at Wed Feb 07 20:56:14 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.