YANGTOOLS-827: fix revision compare 80/65280/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Nov 2017 18:28:53 +0000 (19:28 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Nov 2017 18:36:38 +0000 (19:36 +0100)
When revision statements do not follow guidance from RFC6020/RFC7950
section 7.1.9 and are not order in the order of descending date and
the delta between previous and next version strings is not exactly 1,
we end up picking the wrong version.

This is caused by wrong compareTo() check, which should compare '< 0',
not '== -1'.

Change-Id: Ib7f9a77a9950b6da93ffa30e4c13cc940887ad19
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 3c855240dd70f79e7acd9fa98adb8c6a3580f60b)

yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfoTest.java
yang/yang-parser-impl/src/test/resources/bugs/YT827/foo.yang [new file with mode: 0644]

index fdabf9029eb4728a706e505f96a94bea140da4f2..6049c6a32da6398c9b22d30e0deef4ad53c8ab9e 100644 (file)
@@ -283,7 +283,7 @@ public abstract class YangModelDependencyInfo {
             if (REVISION.equals(subStatementContext.keyword().getText())) {
                 final String currentRevision = Utils.stringFromStringContext(subStatementContext.argument(),
                         getReference(source, subStatementContext));
-                if (latestRevision == null || latestRevision.compareTo(currentRevision) == -1) {
+                if (latestRevision == null || latestRevision.compareTo(currentRevision) < 0) {
                     latestRevision = currentRevision;
                 }
             }
index c843ae7c78c6f187d06f13d20e30b0cd9275736e..83806afffa62f4c9e9b004a3a8993c9e488c51fb 100644 (file)
@@ -64,6 +64,14 @@ public class YangModelDependencyInfoTest {
         assertFalse(info1.equals(info2));
     }
 
+    @Test
+    public void testYangtools827() throws IOException, YangSyntaxErrorException {
+        // Latest revision needs to be picked up irrespective of ordering
+        YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
+            "/bugs/YT827/foo.yang");
+        assertEquals("2014-12-24", info.getFormattedRevision());
+    }
+
     @Test
     public void testHashcode() throws IOException, YangSyntaxErrorException {
         YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(),
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/YT827/foo.yang b/yang/yang-parser-impl/src/test/resources/bugs/YT827/foo.yang
new file mode 100644 (file)
index 0000000..c096177
--- /dev/null
@@ -0,0 +1,8 @@
+module foo {
+    namespace foo;
+    prefix foo;
+
+    revision "2010-10-10";
+
+    revision "2014-12-24";
+}