jlahoda commented on issue #369: Making Maven projects usable without properly installed Java support. URL: https://github.com/apache/incubator-netbeans/pull/369#issuecomment-357763425 @JaroslavTulach, please note that I didn't ask to use the hasWorkingJavac method, or a centralized place to put try-catch (LinkageError). I asked if *synthesizing* the interface would help. And, indeed, it appears it would: ` diff --git a/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java b/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java index d60f6a8..4d45f8a 100644 --- a/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java +++ b/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java @@ -19,6 +19,7 @@ package org.netbeans.modules.java.source; import java.lang.reflect.Field; +import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; import org.objectweb.asm.ClassWriter; @@ -71,6 +72,25 @@ public class NoJavacHelper { //ignore... Logger.getLogger(NoJavacHelper.class.getName()).log(Level.FINE, null, t); } + synthetizeEmptyInterface("com.sun.source.tree.DirectiveTree", "com.sun.source.tree.Tree"); + synthetizeEmptyInterface("com.sun.source.tree.RequiresTree", "com.sun.source.tree.DirectiveTree"); + } + } + + private void synthetizeEmptyInterface(String intf, String... superInterfaces) { + ClassWriter w = new ClassWriter(0); + w.visit(Opcodes.V1_8, Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_PUBLIC, intf.replace('.', '/'), null, "java/lang/Object", Arrays.stream(superInterfaces).map(n -> n.replace('.', '/')).toArray(s -> new String[s])); + byte[] classData = w.toByteArray(); + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + Unsafe unsafe = (Unsafe) theUnsafe.get(null); + Class scopeClass = Class.forName(superInterfaces[0]); + unsafe.defineClass(intf, classData, 0, classData.length, scopeClass.getClassLoader(), scopeClass.getProtectionDomain()); + } catch (Throwable t) { + t.printStackTrace(); + //ignore... + Logger.getLogger(NoJavacHelper.class.getName()).log(Level.FINE, null, t); } } ` I guess I don't see how scattering catches for LinkageErrors around the codebase is better than having a centralized place where all the needed stuff is injected. What exactly is the process to remove all the catches? Or will we just leave them in forever masking any LinkageErrors whether related to this or not?
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
