JDK-8273360 : [lworld] Invoking a reflection-generated constructor for primitive class gives InstantiationError
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: repo-valhalla
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2021-09-05
  • Updated: 2021-09-23
  • Resolved: 2021-09-23
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
repo-valhallaFixed
Related Reports
Relates :  
Description
As noted in JDK-8207315, the constructor invocation generated by jdk.internal.reflect.MethodAccessorGenerator doesn't work for primitive classes.

Thus, invoking a static factory method for a primitive class more than 15 times will break (as controlled by jdk.internal.reflect.ReflectionFactory.inflationThreshold())
Comments
Fix in PR: https://github.com/openjdk/valhalla/pull/546 The fix is not very pretty, just adds a separate path for reflectively calling the factory method instead of a ctor, but doesn't move the code generation from the JDK's own ClassFileAssembler to ASM, for example. I also tested the regular method access, but it required no changes in my test.
05-09-2021