Skip to content

Commit 63b4316

Browse files
committed
Reduce --add-opens list
- remove --add-opens flags if possible. - some usages (e.g. reflective constructor invocation) allow to change opens into exports when only public API is used - add comments to some of the encapsulation breaking usage
1 parent 1e51daa commit 63b4316

File tree

19 files changed

+31
-80
lines changed

19 files changed

+31
-80
lines changed

groovy/groovy.editor/test/unit/data/testfiles/completion/transformations/singleton3/Singleton3.groovy.testSingleton3_withoutPrefix.21.completion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ FIELD protectionDomain [PUBLIC] ProtectionDomain
210210
FIELD record [PUBLIC] boolean
211211
FIELD recordComponents [PUBLIC] RecordComponent[]
212212
FIELD sealed [PUBLIC] boolean
213+
FIELD signers [PUBLIC] Object[]
213214
FIELD simpleName [PUBLIC] String
214215
FIELD superclass [PUBLIC] Class
215216
FIELD synthetic [PUBLIC] boolean

groovy/groovy.editor/test/unit/data/testfiles/completion/transformations/singleton3/Singleton3.groovy.testSingleton3_withoutPrefix.completion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ FIELD protectionDomain [PUBLIC] ProtectionDomain
208208
FIELD record [PUBLIC] boolean
209209
FIELD recordComponents [PUBLIC] RecordComponent[]
210210
FIELD sealed [PUBLIC] boolean
211+
FIELD signers [PUBLIC] Object[]
211212
FIELD simpleName [PUBLIC] String
212213
FIELD superclass [PUBLIC] Class
213214
FIELD synthetic [PUBLIC] boolean

ide/editor.settings.lib/src/org/netbeans/modules/editor/settings/storage/preferences/PreferencesImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ private void asyncInvocationOfFlushSpi() {
478478
flushTask.schedule(200);
479479
}
480480

481+
// TODO this adds --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED
481482
// XXX: we probably should not extends AbstractPreferences and do it all ourselfs
482483
// including the firing of events. For the events delivery we could just reuse common
483484
// RequestProcessor threads.

ide/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ public static boolean isWriteLocked(Document doc) {
521521
} catch (NoSuchFieldException ex) {
522522
throw new IllegalStateException(ex);
523523
}
524+
// TODO adds --add-opens=java.desktop/javax.swing.text=ALL-UNNAMED
524525
f.setAccessible(true);
525526
currWriterField = f;
526527
}

ide/xsl/nbproject/project.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ javac.compilerargs=-Xlint -Xlint:-serial
1919
javac.source=1.8
2020

2121
test.config.stableBTD.includes=**/*Test.class
22+
23+
# at org.apache.tomcat.util.security.PrivilegedSetAccessControlContext.<clinit>(PrivilegedSetAccessControlContext.java:41)
24+
test.jms.flags=--add-opens=java.base/java.lang=ALL-UNNAMED

java/form/src/org/netbeans/modules/form/FormLAF.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public static PreviewInfo initPreviewLaf(Class lafClass, ClassLoader formClassLo
7575
!MetalLookAndFeel.class.equals(lafClass) && (lafToTheme.get(MetalLookAndFeel.class) == null)) {
7676
lafToTheme.put(MetalLookAndFeel.class, MetalLookAndFeel.getCurrentTheme());
7777
}
78+
// adds
79+
// --add-exports=java.desktop/com.sun.java.swing.plaf.gtk=ALL-UNNAMED
80+
// --add-exports=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED
81+
// --add-exports=java.desktop/com.apple.eio=ALL-UNNAMED
82+
// --add-exports=java.desktop/com.sun.java.swing.plaf.motif=ALL-UNNAMED
7883
LookAndFeel previewLookAndFeel = (LookAndFeel)lafClass.getDeclaredConstructor().newInstance();
7984
if (previewLafIsMetal) {
8085
MetalTheme theme = lafToTheme.get(lafClass);
@@ -209,6 +214,7 @@ private static void initialize() throws Exception {
209214
}
210215

211216
java.lang.reflect.Method method = UIManager.class.getDeclaredMethod("getLAFState", new Class[0]); // NOI18N
217+
// TODO adds --add-opens=java.desktop/javax.swing=ALL-UNNAMED
212218
method.setAccessible(true);
213219
Object lafState = method.invoke(null, new Object[0]);
214220
method = lafState.getClass().getDeclaredMethod("setLookAndFeelDefaults", new Class[] {UIDefaults.class}); // NOI18N
@@ -373,6 +379,7 @@ private static void copyMultiUIDefaults(UIDefaults what, Map where) {
373379
// in MultiUIDefaults in JDK 6 Update 10
374380
try {
375381
java.lang.reflect.Method method = Hashtable.class.getDeclaredMethod("getIterator", new Class[] {int.class}); // NOI18N
382+
// TODO adds --add-opens=java.base/java.util=ALL-UNNAMED
376383
method.setAccessible(true);
377384
Object i = method.invoke(what, new Object[] {2/*Hashtable.ENTRIES*/});
378385
if (i instanceof Iterator) {

java/form/src/org/netbeans/modules/form/HandleLayer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,7 @@ private static void paintDraggedComponent(Component comp, Graphics g, float opac
28722872
static {
28732873
try {
28742874
Field field = Component.class.getDeclaredField("valid"); // NOI18N
2875+
// TODO adds --add-opens=java.desktop/java.awt=ALL-UNNAMED
28752876
field.setAccessible(true);
28762877
componentValidField = field;
28772878
} catch (NoSuchFieldException ex) {

java/java.source.base/src/org/netbeans/api/java/source/TreeUtilities.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ public void report(JCDiagnostic diag) {
990990
Env<AttrContext> result = attr.attributeAndCapture((JCTree) tree, env, (JCTree) to);
991991
try {
992992
Constructor<JavacScope> c = JavacScope.class.getDeclaredConstructor(Env.class);
993+
// TODO this adds --add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
993994
c.setAccessible(true);
994995
return c.newInstance(result);
995996
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {

java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@
1818
*/
1919
package org.netbeans.modules.java.source;
2020

21-
import java.lang.reflect.Field;
22-
import java.lang.reflect.Method;
23-
import java.security.ProtectionDomain;
24-
import java.util.logging.Level;
25-
import java.util.logging.Logger;
2621
import javax.lang.model.SourceVersion;
27-
import org.objectweb.asm.ClassWriter;
28-
import org.objectweb.asm.Opcodes;
29-
import org.openide.modules.OnStart;
3022

3123
/**
3224
*
@@ -51,57 +43,4 @@ public class NoJavacHelper {
5143
public static boolean hasWorkingJavac() {
5244
return HAS_WORKING_JAVAC;
5345
}
54-
55-
// safety net if someone manages to start NB on JDK 8 with nb-javac uninstalled
56-
@OnStart
57-
public static class FixClasses implements Runnable {
58-
59-
@Override
60-
public void run() {
61-
if (!hasWorkingJavac()) {
62-
String JavaVersion = System.getProperty("java.specification.version"); //NOI18N
63-
boolean isJdkVer8OrBelow = true;
64-
if (!JavaVersion.startsWith("1.")) { //NOI18N
65-
isJdkVer8OrBelow = false;
66-
}
67-
if (isJdkVer8OrBelow) {
68-
{
69-
ClassWriter w = new ClassWriter(0);
70-
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);
71-
byte[] classData = w.toByteArray();
72-
73-
defineClass("com.sun.tools.javac.code.Scope$WriteableScope",
74-
"com.sun.tools.javac.code.Scope",
75-
classData);
76-
}
77-
{
78-
ClassWriter w = new ClassWriter(0);
79-
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"});
80-
byte[] classData = w.toByteArray();
81-
82-
defineClass("javax.lang.model.element.ModuleElement",
83-
"com.sun.tools.javac.code.Scope",
84-
classData);
85-
}
86-
}
87-
}
88-
}
89-
90-
private void defineClass(String fqn, String injectToClass, byte[] classData) {
91-
try {
92-
Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
93-
Field theUnsafe = unsafeClass.getDeclaredField("theUnsafe"); //NOI18N
94-
theUnsafe.setAccessible(true);
95-
Object unsafe = theUnsafe.get(null);
96-
97-
Class targetClass = Class.forName(injectToClass); //NOI18N
98-
99-
Method defineClass = unsafeClass.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class, ClassLoader.class, ProtectionDomain.class); //NOI18N
100-
defineClass.invoke(unsafe, fqn, classData, 0, classData.length, targetClass.getClassLoader(), targetClass.getProtectionDomain()); //NOI18N
101-
} catch (Throwable t) {
102-
//ignore...
103-
Logger.getLogger(NoJavacHelper.class.getName()).log(Level.WARNING, null, t);
104-
}
105-
}
106-
}
10746
}

java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ public ReferenceTree Reference(ExpressionTree qualExpr, CharSequence member, Lis
20042004
paramTypesParam = lbl.toList();
20052005
}
20062006
Constructor<DCReference> c = DCReference.class.getDeclaredConstructor(String.class, JCExpression.class, JCTree.class, javax.lang.model.element.Name.class, List.class);
2007+
// TODO this adds --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
20072008
c.setAccessible(true);
20082009
DCReference result = c.newInstance("", (JCTree.JCExpression) qualExpr, qualExpr == null ? null : ((JCTree.JCExpression) qualExpr).getTree(), member != null ? (com.sun.tools.javac.util.Name) names.fromString(member.toString()) : null, paramTypesParam);
20092010
result.pos = NOPOS;

0 commit comments

Comments
 (0)