Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8273360: [lworld] Invoking a reflection-generated constructor for primitive class gives InstantiationError #546

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -52,6 +52,7 @@ class MethodAccessorGenerator extends AccessorGenerator {
private Class<?>[] parameterTypes;
private Class<?> returnType;
private boolean isConstructor;
private boolean isStaticFactory;
private boolean forSerialization;

private short targetMethodRef;
@@ -80,6 +81,7 @@ public MethodAccessor generateMethod(Class<?> declaringClass,
modifiers,
false,
false,
false,
null);
}

@@ -89,13 +91,15 @@ public ConstructorAccessor generateConstructor(Class<?> declaringClass,
Class<?>[] checkedExceptions,
int modifiers)
{
boolean isStaticFactory = declaringClass.isPrimitiveClass();
return (ConstructorAccessor) generate(declaringClass,
"<init>",
parameterTypes,
Void.TYPE,
isStaticFactory ? declaringClass.asValueType() : Void.TYPE,
checkedExceptions,
modifiers,
true,
isStaticFactory,
false,
null);
}
@@ -116,6 +120,7 @@ public ConstructorAccessor generateConstructor(Class<?> declaringClass,
checkedExceptions,
modifiers,
true,
false,
true,
targetConstructorClass);
}
@@ -129,6 +134,7 @@ private MagicAccessorImpl generate(final Class<?> declaringClass,
Class<?>[] checkedExceptions,
int modifiers,
boolean isConstructor,
boolean isStaticFactory,
boolean forSerialization,
Class<?> serializationTargetClass)
{
@@ -139,6 +145,7 @@ private MagicAccessorImpl generate(final Class<?> declaringClass,
this.returnType = returnType;
this.modifiers = modifiers;
this.isConstructor = isConstructor;
this.isStaticFactory = isStaticFactory;
this.forSerialization = forSerialization;

asm.emitMagicAndVersion();
@@ -431,7 +438,7 @@ private void emitInvoke() {

short illegalArgStartPC = 0;

if (isConstructor) {
if (isConstructor && !isStaticFactory) {
// Instantiate target class before continuing
// new <target class type>
// dup
@@ -621,7 +628,7 @@ private void emitInvoke() {
short invokeStartPC = cb.getLength();

// OK, ready to perform the invocation.
if (isConstructor) {
if (isConstructor && !isStaticFactory) {
cb.opc_invokespecial(targetMethodRef, count, 0);
} else {
if (isStatic()) {
@@ -24,8 +24,10 @@

/*
* @test
* @bug 8273360
* @summary Test reflection of constructors for primitive classes
* @run testng/othervm StaticFactoryTest
* @run testng/othervm -Dsun.reflect.noInflation=true StaticFactoryTest
jespersm marked this conversation as resolved.
Show resolved Hide resolved
*/

import java.lang.reflect.Constructor;