JDK-5043030 : (reflect) unnecessary object creation in reflection
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2004-05-06
  • Updated: 2017-05-16
  • Resolved: 2014-09-09
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.
JDK 9
9 b31Fixed
Related Reports
Relates :  
Relates :  
Sub Tasks
JDK-8164412 :  
Description
Tiger introduces a cache of commonly used wrapper instances, and a static
factory for returning them.  The language requires caching Integers in the
range -128 to 127.  But this cache is not used in the reflection
implementation, resulting in much unnecessary object creation when running
reflective code.

Here is a test case that illustrates the problem:

/////////////////////////////////////////////////////////
import java.lang.reflect.*;
class Main {
    public static int f() { return 0; }
    public static void main(String[] args) throws Exception {
        Method m = Main.class.getMethod("f");
        Object o1 = m.invoke(null);
        Object o2 = m.invoke(null);
        if (o1 != o2)
            throw new Error(System.identityHashCode(o1) +
                            " " + System.identityHashCode(o2));
    }
}

Comments
Review of fix contributed by Andrej Golovnin is on core-libs-dev. CCC is filed.
01-09-2014

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
14-06-2004

EVALUATION A useful change for a post-Tiger release. ###@###.### 2004-05-19
19-05-2004