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

AArch64: String.compareTo() may return incorrect result

XMLWordPrintable

    • 11
    • b08
    • aarch64
    • linux

        AArch64 String.compareTo() may return incorrect result in some corner
        cases. This issue can be reproduced in below program by constructing two
        strings from the same byte array but with different encoding options.

        import java.lang.reflect.Constructor;

        public class Test {
          public static void main(String[] args) throws Exception {
            Constructor<String> c = String.class.getDeclaredConstructor(byte[].class, byte.class);
            c.setAccessible(true);

            byte[] bytes = new byte[] {
              'Y', 'm', '_', 'l', 'V', 'n', 'W', 'S', 'w', 'm', 'W', 'S'
            };

            String s1 = c.newInstance(bytes, (byte) 0);
            String s2 = c.newInstance(bytes, (byte) 1);
            System.out.println(s1.compareTo(s2));
          }
        }

        // $ java -Xint Test
        // -27904
        // $ java -Xcomp -XX:-TieredCompilation Test
        // 6

              pli Pengfei Li
              pli Pengfei Li
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: