Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8250677

ModuleDescriptor.Version parsing treats pre-release identically to build

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE PROBLEM :
      ModuleDescriptor.Version.compareTo() does not correctly distinguish between pre-release and build segments:

      * "1+1" == "1-1"
      * "1+foo" == "1-foo"
      * "1+foo+bar" == "1-foo+bar"
      * but "1+foo-bar" != "1-foo+bar"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use this script:
      ---- 8< ---- 8< ----
      //usr/bin/env jbang "$0" "$@" ; exit $?

      import java.util.*;
      import java.lang.module.ModuleDescriptor;

      public class JpmsCompare {
          static final Comparator<String> c = (a, b) -> Integer.signum(ModuleDescriptor.Version.parse(a).compareTo(ModuleDescriptor.Version.parse(b)));

          public static void main(String[] args) {
              Iterator<String> i = Arrays.asList(args).iterator();
              if (i.hasNext()) {
                  String a = i.next();
                  System.out.printf("%s == %s%n", a, ModuleDescriptor.Version.parse(a));
                  while (i.hasNext()) {
                      String b = i.next();
                      int res = c.compare(a, b);
                      if (res < 0) {
                          System.out.printf(" %s < %s%n", a, b);
                      } else if (res > 0) {
                          System.out.printf(" %s > %s%n", a, b);
                      } else {
                          System.out.printf(" %s == %s%n", a, b);
                      }
                      a = b;
                      System.out.printf("%s == %s%n", a, ModuleDescriptor.Version.parse(a));
                  }
              }
          }
      }



      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: