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

Incorrect comparator com.sun.beans.introspect.MethodInfo.MethodOrder

    Details

    • Subcomponent:
    • Resolved In Build:
      b23
    • CPU:
      x86
    • OS:
      os_x

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        macOS 10.13.6 (17G65) (but the bug is reproducible on Linux too)

        $ java -version
        java version "10.0.2" 2018-07-17
        Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
        Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)

        A DESCRIPTION OF THE PROBLEM :
        Method java.beans.Introspector.getBeanInfo(...) sometimes thows exception for complex classes.
        getBeanInfo sort methods, but comparator violates its contract (sgn(compare(x, y)) == -sgn(compare(y, x)) for all x, y), so sort can throw IllegalArgumentException

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run program many times (1000 should be enough)
        for i in `seq 1000`; do java bug.Main; done

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        No exceptions expected
        ACTUAL -
        3-4 times program crashes with exception:
        Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract! ]
        at java.base/java.util.TimSort.mergeHi(TimSort.java:899)
        at java.base/java.util.TimSort.mergeAt(TimSort.java:516)
        at java.base/java.util.TimSort.mergeCollapse(TimSort.java:441)
        at java.base/java.util.TimSort.sort(TimSort.java:245)
        at java.base/java.util.Arrays.sort(Arrays.java:1514)
        at java.base/java.util.ArrayList.sort(ArrayList.java:1585)
        at java.desktop/com.sun.beans.introspect.MethodInfo.get(MethodInfo.java:94)
        at java.desktop/com.sun.beans.introspect.ClassInfo.getMethods(ClassInfo.java:71)
        at java.desktop/java.beans.Introspector.getTargetMethodInfo(Introspector.java:1046)
        at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:462)
        at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:205)
        at bug.Main.main(Main.java:14)

        ---------- BEGIN SOURCE ----------
        package bug;

        import java.beans.Introspector;
        import java.io.Serializable;
        import java.util.AbstractCollection;
        import java.util.AbstractList;
        import java.util.ArrayList;
        import java.util.Collection;
        import java.util.List;
        import java.util.RandomAccess;

        public class Main {
            public static void main(String[] args) throws Exception {
                Introspector.getBeanInfo(X.class);
            }

            interface X_1 {AbstractList x_8(); }interface X_2 {Cloneable x_0(); }interface X_3 {Serializable x_1(); }interface X_4 {Object x_7(); }interface X_5 {RandomAccess x_6(); }interface X_6 {RandomAccess x_0(); }interface X_7 {Serializable x_5(); }interface X_8 {Object x_4(); }interface X_9 {RandomAccess x_5(); }interface X_10 {Cloneable x_5(); }interface X_11 {RandomAccess x_9(); }interface X_12 {Cloneable x_9(); }interface X_13 {Iterable x_2(); }interface X_14 {Collection x_7(); }interface X_15 {Serializable x_4(); }interface X_16 {Cloneable x_7(); }interface X_17 {Object x_1(); }interface X_18 {ArrayList x_6(); }interface X_19 {List x_5(); }interface X_20 {Collection x_2(); }interface X_21 {List x_1(); }interface X_22 {List x_3(); }interface X_23 {RandomAccess x_3(); }interface X_24 {RandomAccess x_1(); }interface X_25 {Object x_6(); }interface X_26 {Cloneable x_7(); }interface X_27 {Iterable x_0(); }interface X_28 {Iterable x_1(); }interface X_29 {AbstractList x_7(); }interface X_30 {AbstractList x_1(); }interface X_31 {Cloneable x_9(); }interface X_32 {ArrayList x_6(); }interface X_33 {Cloneable x_2(); }interface X_34 {Iterable x_6(); }interface X_35 {Iterable x_9(); }interface X_36 {AbstractList x_9(); }interface X_37 {Iterable x_7(); }interface X_38 {Iterable x_3(); }interface X_39 {Iterable x_9(); }interface X_40 {AbstractList x_3(); }interface X_41 {List x_0(); }interface X_42 {Iterable x_0(); }interface X_43 {Iterable x_2(); }interface X_44 {ArrayList x_4(); }interface X_45 {AbstractList x_4(); }interface X_46 {Collection x_4(); }interface X_47 {ArrayList x_2(); }interface X_48 {ArrayList x_6(); }interface X_49 {Serializable x_1(); }interface X_50 {Cloneable x_7(); }interface X_51 {Collection x_5(); }interface X_52 {RandomAccess x_5(); }interface X_53 {Collection x_5(); }interface X_54 {RandomAccess x_4(); }interface X_55 {Collection x_0(); }interface X_56 {Collection x_7(); }interface X_57 {Iterable x_9(); }interface X_58 {List x_3(); }interface X_59 {Serializable x_7(); }interface X_60 {AbstractCollection x_6(); }interface X_61 {AbstractList x_9(); }interface X_62 {List x_7(); }interface X_63 {AbstractCollection x_3(); }interface X_64 {RandomAccess x_4(); }interface X_65 {Object x_3(); }interface X_66 {RandomAccess x_6(); }interface X_67 {Cloneable x_6(); }interface X_68 {Cloneable x_3(); }interface X_69 {Collection x_5(); }interface X_70 {AbstractCollection x_0(); }interface X_71 {Object x_8(); }interface X_72 {AbstractCollection x_3(); }interface X_73 {Serializable x_4(); }interface X_74 {AbstractList x_8(); }interface X_75 {ArrayList x_1(); }interface X_76 {List x_5(); }interface X_77 {Object x_0(); }interface X_78 {Collection x_0(); }interface X_79 {ArrayList x_2(); }interface X_80 {ArrayList x_8(); }interface X_81 {Cloneable x_3(); }interface X_82 {Serializable x_1(); }interface X_83 {List x_1(); }interface X_84 {Collection x_5(); }interface X_85 {RandomAccess x_9(); }interface X_86 {AbstractList x_3(); }interface X_87 {Cloneable x_6(); }interface X_88 {Object x_2(); }interface X_89 {ArrayList x_5(); }interface X_90 {Iterable x_1(); }interface X_91 {ArrayList x_4(); }interface X_92 {Iterable x_6(); }interface X_93 {Collection x_7(); }interface X_94 {Iterable x_2(); }interface X_95 {AbstractList x_7(); }interface X_96 {RandomAccess x_2(); }interface X_97 {RandomAccess x_2(); }interface X_98 {List x_6(); }interface X_99 {Object x_4(); }interface X_100 {Collection x_7(); }static class X implements X_1,X_2,X_3,X_4,X_5,X_6,X_7,X_8,X_9,X_10,X_11,X_12,X_13,X_14,X_15,X_16,X_17,X_18,X_19,X_20,X_21,X_22,X_23,X_24,X_25,X_26,X_27,X_28,X_29,X_30,X_31,X_32,X_33,X_34,X_35,X_36,X_37,X_38,X_39,X_40,X_41,X_42,X_43,X_44,X_45,X_46,X_47,X_48,X_49,X_50,X_51,X_52,X_53,X_54,X_55,X_56,X_57,X_58,X_59,X_60,X_61,X_62,X_63,X_64,X_65,X_66,X_67,X_68,X_69,X_70,X_71,X_72,X_73,X_74,X_75,X_76,X_77,X_78,X_79,X_80,X_81,X_82,X_83,X_84,X_85,X_86,X_87,X_88,X_89,X_90,X_91,X_92,X_93,X_94,X_95,X_96,X_97,X_98,X_99,X_100 {public ArrayList x_0() {return null;}
                public ArrayList x_1() {return null;}
                public ArrayList x_2() {return null;}
                public ArrayList x_3() {return null;}
                public ArrayList x_4() {return null;}
                public ArrayList x_5() {return null;}
                public ArrayList x_6() {return null;}
                public ArrayList x_7() {return null;}
                public ArrayList x_8() {return null;}
                public ArrayList x_9() {return null;}}
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        This patch should help
        @@ -141,7 +141,10 @@
                     if (aret.isAssignableFrom(bret)) {
                         return 1;
                     }
        - return -1;
        + if (bret.isAssignableFrom(aret)) {
        + return -1;
        + }
        + return aret.getName().compareTo(bret.getName());
                 }

                 static final MethodOrder instance = new MethodOrder();

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  serb Sergey Bylokhov
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: