This is an automated email from the ASF dual-hosted git repository. matthiasblaesing pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 6e760f6 [NETBEANS-3234] Fix for ProxyClassLoader to implement findClass(String name) required for Java 11. 6e760f6 is described below commit 6e760f6b4d5b032bfb8a8f88b1604318c5e13fa6 Author: Boris Heithecker <boris.heithec...@gmx.net> AuthorDate: Sat Oct 12 13:42:07 2019 +0200 [NETBEANS-3234] Fix for ProxyClassLoader to implement findClass(String name) required for Java 11. --- .../src/org/netbeans/ProxyClassLoader.java | 16 +++- ...ProxyClassLoaderNB11PackageAnnotationsTest.java | 88 ++++++++++++++++++++++ .../pkgannottest/NB11PackageTestAnnotation.java | 29 +++++++ .../org/netbeans/pkgannottest/package-info.java | 20 +++++ 4 files changed, 151 insertions(+), 2 deletions(-) diff --git a/platform/o.n.bootstrap/src/org/netbeans/ProxyClassLoader.java b/platform/o.n.bootstrap/src/org/netbeans/ProxyClassLoader.java index b5a213e..2a019ba 100644 --- a/platform/o.n.bootstrap/src/org/netbeans/ProxyClassLoader.java +++ b/platform/o.n.bootstrap/src/org/netbeans/ProxyClassLoader.java @@ -122,6 +122,18 @@ public class ProxyClassLoader extends ClassLoader { @Override protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + final Class cls = doFindClass(name); + if (resolve) resolveClass(cls); + return cls; + } + + @Override + protected Class<?> findClass(String name) throws ClassNotFoundException { + LOGGER.log(Level.FINEST, "{0} finding class {1}", new Object[] {this, name}); + return doFindClass(name); + } + + private Class<?> doFindClass(String name) throws ClassNotFoundException { if (LOG_LOADING && !name.startsWith("java.")) { LOGGER.log(Level.FINEST, "{0} initiated loading of {1}", new Object[] {this, name}); @@ -202,9 +214,9 @@ public class ProxyClassLoader extends ClassLoader { if (cls == null) { throw new ClassNotFoundException(diagnosticCNFEMessage(name, del)); } - if (resolve) resolveClass(cls); - return cls; + return cls; } + private String diagnosticCNFEMessage(String base, Set<ProxyClassLoader> del) { String parentSetS; int size = parents.size(); diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderNB11PackageAnnotationsTest.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderNB11PackageAnnotationsTest.java new file mode 100644 index 0000000..6dc5e26 --- /dev/null +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/ProxyClassLoaderNB11PackageAnnotationsTest.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.util.Collections; +import org.netbeans.junit.NbTestCase; + +/** + * This test ensures that package level annotations (annotations to + * package-info) are correctly loaded by the NetBeans classloader system in Java + * 11. + */ +public class ProxyClassLoaderNB11PackageAnnotationsTest extends NbTestCase { + + private static final String TEST_PACKAGE = "org.netbeans.pkgannottest"; + + public ProxyClassLoaderNB11PackageAnnotationsTest(String name) { + super(name); + } + + public void testPackageAnnotation() throws Exception { + + class PackageClassLoader extends ProxyClassLoader { + + PackageClassLoader() { + super(new ClassLoader[0], false); + addCoveredPackages(Collections.singleton(TEST_PACKAGE)); + } + + @Override + protected Class doLoadClass(String pkg, String name) { + if (name.startsWith(TEST_PACKAGE)) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + InputStream is = PackageClassLoader.class.getClassLoader().getResourceAsStream(name.replace('.', '/') + ".class"); + byte[] buf = new byte[4096]; + int read; + try { + while ((read = is.read(buf)) != -1) { + baos.write(buf, 0, read); + } + } catch (IOException x) { + assert false : x; + } + return defineClass(name, baos.toByteArray(), 0, baos.size()); + } + return null; + } + + @Override + protected boolean shouldDelegateResource(String pkg, ClassLoader parent) { + return parent != null || !pkg.equals(TEST_PACKAGE.replace('.', '/') + "/"); + } + + @Override + public String toString() { + return PackageClassLoader.class.getName(); + } + + } + + final ProxyClassLoader cl = new PackageClassLoader(); + final Class<? extends Annotation> annotClz = (Class<? extends Annotation>) cl.loadClass(TEST_PACKAGE + ".NB11PackageTestAnnotation"); + final Package pkg = annotClz.getPackage(); + final Object annot = pkg.getAnnotation(annotClz); + assertTrue("Annotation not found", annot != null); + } + +} diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/pkgannottest/NB11PackageTestAnnotation.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/pkgannottest/NB11PackageTestAnnotation.java new file mode 100644 index 0000000..11105be --- /dev/null +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/pkgannottest/NB11PackageTestAnnotation.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.pkgannottest; + +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * + * @author boris.heithec...@gmx.net + */ +@Retention(value = RUNTIME) +public @interface NB11PackageTestAnnotation {} diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/pkgannottest/package-info.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/pkgannottest/package-info.java new file mode 100644 index 0000000..8083e0e --- /dev/null +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/pkgannottest/package-info.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +@NB11PackageTestAnnotation +package org.netbeans.pkgannottest; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists