mbien commented on a change in pull request #3396:
URL: https://github.com/apache/netbeans/pull/3396#discussion_r777140803
##########
File path:
java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java
##########
@@ -18,99 +18,34 @@
*/
package org.netbeans.modules.java.source;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.security.ProtectionDomain;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.lang.model.SourceVersion;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Opcodes;
-import org.openide.modules.OnStart;
/**
*
* @author lahvac
*/
public class NoJavacHelper {
- private static final AtomicReference<Boolean> hasWorkingJavac = new
AtomicReference<>();
- public static boolean hasWorkingJavac() {
- Boolean res = hasWorkingJavac.get();
- if (res != null) {
- return res;
- }
+ private static final boolean hasWorkingJavac;
+
+ static {
+ boolean res;
try {
SourceVersion.valueOf("RELEASE_17");
res = true;
} catch (IllegalArgumentException ex) {
- //OK
res = false;
}
- hasWorkingJavac.compareAndSet(null, res);
- return hasWorkingJavac.get();
+ hasWorkingJavac = res;
}
- public static boolean hasNbJavac() {
- try {
- Class.forName("com.sun.tools.javac.comp.Repair");
- return true;
- } catch (ClassNotFoundException ex) {
- //OK
- return false;
- }
+ public static boolean hasWorkingJavac() {
+ return hasWorkingJavac;
}
- @OnStart
- public static class FixClasses implements Runnable {
-
- @Override
- public void run() {
- if (!hasWorkingJavac()) {
- String JavaVersion =
System.getProperty("java.specification.version"); //NOI18N
- boolean isJdkVer8OrBelow = true;
- if (!JavaVersion.startsWith("1.")) { //NOI18N
- isJdkVer8OrBelow = false;
- }
- if (isJdkVer8OrBelow) {
- {
- ClassWriter w = new ClassWriter(0);
- w.visit(Opcodes.V1_8, Opcodes.ACC_ABSTRACT |
Opcodes.ACC_PUBLIC, "com/sun/tools/javac/code/Scope$WriteableScope", null,
"com/sun/tools/javac/code/Scope", null);
- byte[] classData = w.toByteArray();
-
-
defineClass("com.sun.tools.javac.code.Scope$WriteableScope",
- "com.sun.tools.javac.code.Scope",
- classData);
- }
- {
- ClassWriter w = new ClassWriter(0);
- w.visit(Opcodes.V1_8, Opcodes.ACC_ABSTRACT |
Opcodes.ACC_INTERFACE | Opcodes.ACC_PUBLIC,
"javax/lang/model/element/ModuleElement", null, "java/lang/Object", new
String[] {"javax/lang/model/element/Element"});
- byte[] classData = w.toByteArray();
-
- defineClass("javax.lang.model.element.ModuleElement",
- "com.sun.tools.javac.code.Scope",
- classData);
- }
- }
- }
- }
-
- private void defineClass(String fqn, String injectToClass, byte[]
classData) {
- try {
- Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
- Field theUnsafe = unsafeClass.getDeclaredField("theUnsafe");
//NOI18N
- theUnsafe.setAccessible(true);
- Object unsafe = theUnsafe.get(null);
-
- Class targetClass = Class.forName(injectToClass); //NOI18N
-
- Method defineClass =
unsafeClass.getDeclaredMethod("defineClass", String.class, byte[].class,
int.class, int.class, ClassLoader.class, ProtectionDomain.class); //NOI18N
- defineClass.invoke(unsafe, fqn, classData, 0,
classData.length, targetClass.getClassLoader(),
targetClass.getProtectionDomain()); //NOI18N
- } catch (Throwable t) {
- //ignore...
-
Logger.getLogger(NoJavacHelper.class.getName()).log(Level.WARNING, null, t);
- }
- }
+ @Deprecated
Review comment:
will do.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
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