JDK-5096932 : Bad comparator in SourceOrderDeclScanner
  • Type: Bug
  • Component: tools
  • Sub-Component: apt
  • Affected Version: 5.0u1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-09-03
  • Updated: 2012-10-09
  • Resolved: 2004-09-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u1 01Fixed 6Fixed
Related Reports
Relates :  
Description
The comparator used to sort in the source order declaration scanner misbehaves if neither Declaration has a source position defined.  This situation will occur frequently when operating on class files.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.5.0_01 mustang FIXED IN: 1.5.0_01 mustang INTEGRATED IN: 1.5.0_01 mustang
26-09-2004

PUBLIC COMMENTS Tested in test/tools/apt/Basics/print.sh ###@###.### 2004-09-16
16-09-2004

SUGGESTED FIX src/share/classes/com/sun/mirror/util>sccs sccsdiff -r1.4 -r1.5 SourceOrderDeclScanner.java ------- SourceOrderDeclScanner.java ------- 34a35 > 35a37,99 > static boolean equals(Declaration d1, Declaration d2) { > return d1 == d2 || (d1 != null && d1.equals(d2)); > } > > private static class DeclPartialOrder extends com.sun.mirror.util.SimpleDeclarationVisitor { > private int value = 1000; > private static int staticAdjust(Declaration d) { > return d.getModifiers().contains(Modifier.STATIC)?0:1; > } > > DeclPartialOrder() {} > > public int getValue() { return value; } > > @Override > public void visitTypeParameterDeclaration(TypeParameterDeclaration d) {value = 0;} > > @Override > public void visitEnumConstantDeclaration(EnumConstantDeclaration d) {value = 1;} > > @Override > public void visitClassDeclaration(ClassDeclaration d) {value = 2 + staticAdjust(d);} > > @Override > public void visitInterfaceDeclaration(InterfaceDeclaration d) {value = 4;} > > @Override > public void visitEnumDeclaration(EnumDeclaration d) {value = 6;} > > @Override > public void visitAnnotationTypeDeclaration(AnnotationTypeDeclaration d) {value = 8;} > > @Override > public void visitFieldDeclaration(FieldDeclaration d) {value = 10 + staticAdjust(d);} > > @Override > public void visitConstructorDeclaration(ConstructorDeclaration d) {value = 12;} > > @Override > public void visitMethodDeclaration(MethodDeclaration d) {value = 14 + staticAdjust(d);} > } > > private int compareEqualPosition(Declaration d1, Declaration d2) { > assert d1.getPosition() == d2.getPosition(); > > DeclPartialOrder dpo1 = new DeclPartialOrder(); > DeclPartialOrder dpo2 = new DeclPartialOrder(); > > d1.accept(dpo1); > d2.accept(dpo2); > > int difference = dpo1.getValue() - dpo2.getValue(); > if (difference != 0) > return difference; > else { > int result = d1.getSimpleName().compareTo(d2.getSimpleName()); > if (result != 0) > return result; > return (int)( Long.signum((long)System.identityHashCode(d1) - > (long)System.identityHashCode(d2))); > } > } > 37c101 < if (d1 == d2) --- > if (equals(d1, d2)) 43,44c107,112 < if (p1 == null) < return (p2 == null) ?0:1 ; --- > if (p1 == null && p2 != null) > return 1; > else if (p1 != null && p2 == null) > return -1; > else if(p1 == null && p2 == null) > return compareEqualPosition(d1, d2); 46,48c114 < if (p2 == null) < return -1; < --- > assert p1 != null && p2 != null; 60,61c126 < return (int)( Long.signum((long)System.identityHashCode(d1) - < (long)System.identityHashCode(d2))); --- > return compareEqualPosition(d1, d2); ###@###.### 2004-09-16
16-09-2004

EVALUATION Should be fixed. ###@###.### 2004-09-03
03-09-2004