This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 271883

Summary: Class package-info.class not loaded by ProxyClassLoader when running on Java 9 SE
Product: platform Reporter: adik
Component: Module SystemAssignee: Tomas Hurka <thurka>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: Dev   
Hardware: PC   
OS: Windows 10 x64   
Issue Type: DEFECT Exception Reporter:
Attachments: Basic findClass implementation for JarClassLoader

Description adik 2017-12-04 23:41:20 UTC
A package-info.class is not loaded from an NB module in Java 9 anymore. The internal implementaiton of Package.getAnnotation changed in Java 9 in order to support modules. In Java 9, the class package-info.class is loaded using a module name. When running old (Java 8) code an unnamed module is used and the ClassLoader's (Java 9) method loadClass(Module module, String name) delegates to findClass(String name) which is not overriden by ProxyClassLoader.

As can be seen, the loadClass(String mame) method is bypassed when using Java 9.
Comment 1 adik 2017-12-05 11:30:13 UTC
Created attachment 165536 [details]
Basic findClass implementation for JarClassLoader

This patch modifies JarClassLoader such that it overrides ClassLoader#findClass(String name) method. The findClass employs doLoadClass directly.

This implementation seems to be correct w.r.t. the Reflection API, since when a class is explored a class loader which loaded it is used. In the platform, this should be the class loader of the module to which the class belongs. Also the relevant package-info should belong to the same module.

This implementation will probably break when the platform is modularized using Java 9 modules. But in this case, the ProxyClassLoader will break anyway since then the loading will not take code path through ProxyClassLoader#loadClass(String, boolean).