Name: rl43681 Date: 12/09/2002
FULL PRODUCT VERSION :
All JVMs conforming to the JVM specification, second edition.
FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000
[Version 5.00.2195] SP 3
ADDITIONAL OPERATING SYSTEMS : This applies to all operating
systems for which the JVM is available.
A DESCRIPTION OF THE PROBLEM :
The Java VM specification Second Edition explicitly states that
"2.10.2 Method Signature
The signature of a method consists of the name of the method
and the number and type of formal parameters (§2.10.1) of
the method. A class may not declare two methods with the
same signature."
But the Java Generics compiler is implemented using bridge
methods which violate this rule - Section 6.2 of the
Generics Specification gives two examples, 17 and 18, which
violate 2.10.2.
The violation of the rule causes other compiler tools to
fail. For example, javap fails with a CompilerError when
trying to read code compiled by a Java Generics enabled
compiler.
There are also several other bytecode generating tools which
violate 2.10.2 with the same results.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Reproduce examples 17 and 18 from the Generics specification.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Considering that significant effort has already been placed
into Java Generics, and that there are no architectural or
technical limitations which would warrant the restriction in
2.10.2, I expect that the JVM spec will be ammended to
remove the restriction. I also expect that the appropriate
related tools, i.e. javap, will be updated to support the
ammendment.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
// From executing javap on a class that violates 2.10.2
//
Exception in thread "main" sun.tools.java.CompilerError: duplicate addition
at sun.tools.java.MethodSet.add(MethodSet.java:85)
at sun.tools.java.ClassDefinition.collectInheritedMethods(ClassDefinitio
n.java:1472)
at sun.tools.java.BinaryClass.basicCheck(BinaryClass.java:73)
at sun.tools.java.ClassDeclaration.getClassDefinition(ClassDeclaration.j
ava:130)
at sun.tools.java.Environment.getClassDefinition(Environment.java:123)
at sun.tools.javap.JavaP.displayResults(JavaP.java:193)
at sun.tools.javap.JavaP.perform(JavaP.java:212)
at sun.tools.javap.JavaP.entry(JavaP.java:233)
at sun.tools.javap.JavaP.main(JavaP.java:220)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// Example 17 from the Generics spec
//
// Will generate the following code for class D
// class D {
// D dup/*1*/(){}
// C dup/*2*/(){ return dup/*1*/(); }
// }
class C {
C dup();
}
class D extends C {
D dup();
}
Alternatively, write the bytecode for a class by hand (using BCEL for example)
that violates JVM spec 2.10.2. Sun's JVM will happily load, verify, and execute
the class file, and javap will throw a duplicate addition error.
---------- END SOURCE ----------
(Review ID: 178947)
======================================================================
- duplicates
-
JDK-4427137 javap throws exception on a valid class i.e a class accepted by VM
-
- Closed
-