-
Bug
-
Resolution: Fixed
-
P3
-
openjdk8u382, 11.0.20, 17.0.8, 21, 22
-
b23
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8323402 | 21.0.3-oracle | Mandy Chung | P3 | Resolved | Fixed | b01 |
JDK-8320256 | 21.0.2 | Mandy Chung | P3 | Resolved | Fixed | b08 |
JDK-8324707 | 17.0.12-oracle | Weibing Xiao | P3 | Resolved | Fixed | b01 |
JDK-8324554 | 17.0.11 | Ben Taylor | P3 | Resolved | Fixed | b01 |
JDK-8324710 | 11.0.24-oracle | Weibing Xiao | P3 | Resolved | Fixed | b01 |
JDK-8329005 | 11.0.24 | Ben Taylor | P3 | Resolved | Fixed | b01 |
Seen since JDK 21 and JDK 17.0.8
A DESCRIPTION OF THE PROBLEM :
Ref: https://bugs.openjdk.org/browse/JDK-8302791
This changed the exception handling to include the classloader name in the IllegalArgumentException.
If the caller passes null as the classloader, and an IllegalArgument exception is raised, an NPE is thrown since JDK 17.0.8 ...
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.ClassLoader.nameAndId()" because "loader" is null
at java.base/java.lang.System$2.getLoaderNameID(System.java:2456)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.ensureVisible(Proxy.java:884)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.validateProxyInterfaces(Proxy.java:721)
Previously the IllegalArgumentException was thrown.
Null is a valid classloader argument, and the change here is not safe.
REGRESSION : Last worked in JDK 20 and JDK 17.0.7
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run test case provided as "java TestProxy an.interace.name a.jar"
Use any jar you have, so long as the interface class isn't on the boot classpath.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
IllegalArgumentException from ensureVisible if classloader is null
Test case should produce - GOOD - JDK 17.0.7 or earlier gets here
ACTUAL -
NPE from ensureVisible if classloader is null
Test case produces - BAD - JDK 17.0.8 or later gets here
---------- BEGIN SOURCE ----------
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URL;
import java.net.URLClassLoader;
/**
* Run as ...
*
* TestProxy an.interface a.jar
*
* ... where an.interface is any interface in the jar that isn't on the boot classpath.
*
*/
public class TestProxy
{
public static void main(String[] args)
{
String iclz = args[0]; // An interface class (not on the boot class
// path)
String jar = args[1]; // A jar file containing the interface class
try
{
URL[] urls =
{ new URL("jar:file:" + jar + "!/") };
URLClassLoader cl = URLClassLoader.newInstance(urls);
Class clazz = cl.loadClass(iclz);
Object str = Proxy.newProxyInstance(null, new Class<?>[]
{ clazz }, new InvocationHandler()
{
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
System.out.println("Invoked " + method.getName());
return null;
}
});
System.out.println(str.toString());
}
catch (IllegalArgumentException ex)
{
System.err.println("GOOD - JDK 17.0.7 or earlier gets here");
}
catch (NullPointerException ex)
{
System.err.println("BAD - JDK 17.0.8 or later gets here");
}
catch (Throwable t)
{
System.err.println("Test is broken, shouldn't get here");
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Tolerate the NPE in calling code.
FREQUENCY : always
- backported by
-
JDK-8320256 Proxy.newProxyInstance throws NPE if loader is null and interface not visible from class loader
- Resolved
-
JDK-8323402 Proxy.newProxyInstance throws NPE if loader is null and interface not visible from class loader
- Resolved
-
JDK-8324554 Proxy.newProxyInstance throws NPE if loader is null and interface not visible from class loader
- Resolved
-
JDK-8324707 Proxy.newProxyInstance throws NPE if loader is null and interface not visible from class loader
- Resolved
-
JDK-8324710 Proxy.newProxyInstance throws NPE if loader is null and interface not visible from class loader
- Resolved
-
JDK-8329005 Proxy.newProxyInstance throws NPE if loader is null and interface not visible from class loader
- Resolved
- relates to
-
JDK-8302791 Add specific ClassLoader object to Proxy IllegalArgumentException message
- Resolved
-
JDK-8325343 [lworld] java/lang/reflect/Proxy/ClassRestrictions.java fails with NPE
- Resolved
- links to
-
Commit openjdk/jdk11u-dev/b7f78a39
-
Commit openjdk/jdk17u-dev/cac0e96b
-
Commit openjdk/jdk21u/245885bd
-
Commit openjdk/jdk/8eb6f617
-
Review openjdk/jdk11u-dev/2454
-
Review openjdk/jdk11u-dev/2619
-
Review openjdk/jdk17u-dev/2119
-
Review openjdk/jdk21u/340
-
Review openjdk/jdk/16525