Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netbeans 24 will not start on java 24-ea due to security manager permanently disabled. #8008

Closed
homberghp opened this issue Nov 29, 2024 · 3 comments
Labels
kind:bug Bug report or fix needs:discussion Requires discussion on the NetBeans dev mailing list

Comments

@homberghp
Copy link
Contributor

Apache NetBeans version

Apache NetBeans 24 release candidate

What happened

Setting JAVA_HOME to java 24 (ea-25) make the netbeans startup (using the commandline) exit prematurely with the following message

Error occurred during initialization of VM
java.lang.Error: A command line option has attempted to allow or enable the Security Manager. Enabling a Security Manager is not supported.
	at java.lang.System.initPhase3(java.base@24-ea/System.java:2070)

Language / Project Type / NetBeans Component

netbeans startup

How to reproduce

Freshly install netbeans 24 rc 4 from zip to a dir, /usr/local/netbeans-24-rc4 in my case.
On linux then do : export JAVA_HOME=/usr/lib/jvm/jdk-24; /usr/local/netbeans-24-rc4/bin/netbeans

Did this work correctly in an earlier version?

No / Don't know

Operating System

Linux Ubuntu 24.04 LTS

JDK

OpenJDK 64-Bit Server VM (build 24-ea+25-3155, mixed mode, sharing)

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

always on java 24

Are you willing to submit a pull request?

No

@homberghp homberghp added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Nov 29, 2024
@homberghp
Copy link
Contributor Author

A patch.

This might work. It is a hack. Disable the setting of the System.setSecurityManager in TopSecrurityManager, while leaving the remainder of the utility in the TopSecurityManager in tact. But one should prepare for final removal of said TopSecurityManager. It appears to work in ant tryme. Short test with create new maven javaproject and run that.

2 patches:

  • For the TopSecurityManager, see below
  • for the nbexec launcher. This is for the Unix variant only. Have not yet investigated windows. (Currently can't build on Windows)

Patch for nbexec

diff --git a/platform/o.n.bootstrap/launcher/unix/nbexec b/platform/o.n.bootstrap/launcher/unix/nbexec
index 1d6ad6e530..8b4a830836 100755
--- a/platform/o.n.bootstrap/launcher/unix/nbexec
+++ b/platform/o.n.bootstrap/launcher/unix/nbexec
@@ -192,7 +192,7 @@ fi
 # rename old heap dump to .old
 mv "${userdir}/var/log/heapdump.hprof" "${userdir}/var/log/heapdump.hprof.old" > /dev/null 2>&1
 
-jargs_without_clusters="$jargs -Djava.security.manager=allow"
+jargs_without_clusters="$jargs -Djava.security.manager=disallow"
 jargs="-Dnetbeans.dirs=\"${clusters}\" $jargs_without_clusters"
 
 if [ -z "$cachedirspecified" ]; then

Patch for the TopSecurityManager:

diff --git a/platform/o.n.bootstrap/src/org/netbeans/TopSecurityManager.java b/platform/o.n.bootstrap/src/org/netbeans/TopSecurityManager.java
index babb04da60..c89bd13f3d 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/TopSecurityManager.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/TopSecurityManager.java
@@ -48,6 +48,15 @@ import org.openide.util.WeakSet;
 * @author Ales Novak, Jesse Glick
 */
 public class TopSecurityManager extends SecurityManager {
+    /** Due to permanent deprecation of the java security manager we simply hack an instance,
+     so the utilities in this class are still available.
+     * 
+     * This is a HACK.
+     * This behaves as a eager singleton.
+     */
+    private static TopSecurityManager INSTANCE = new TopSecurityManager();
+    // end of hack.
+    
     private static final boolean check = !Boolean.getBoolean("netbeans.security.nocheck"); // NOI18N
     private static final Logger LOG = Logger.getLogger(TopSecurityManager.class.getName());
 
@@ -166,14 +175,14 @@ public class TopSecurityManager extends SecurityManager {
     
     static boolean officialExit = false;
     static Class<?>[] getStack() {
-        SecurityManager s = System.getSecurityManager();
-        TopSecurityManager t;
-        if (s instanceof TopSecurityManager) {
-            t = (TopSecurityManager)s;
-        } else {
-            t = new TopSecurityManager();
-        }
-        return t.getClassContext();
+//        SecurityManager s = System.getSecurityManager();
+//        TopSecurityManager t;
+//        if (s instanceof TopSecurityManager) {
+//            t = (TopSecurityManager)s;
+//        } else {
+//            t = new TopSecurityManager();
+//        }
+        return INSTANCE.getClassContext();
     }
     
     /** Can be called from core classes to exit the system.
@@ -521,15 +530,17 @@ public class TopSecurityManager extends SecurityManager {
     }
     
     public static void install() {
-        try {
-            System.setSecurityManager(new TopSecurityManager());
-        } catch (SecurityException ex) {
-            LOG.log(Level.WARNING, "Cannot associated own security manager"); // NOI18N
-            LOG.log(Level.INFO, "Cannot associated own security manager", ex); // NOI18N
-        }
+        // sec man is deprecated
+//        try {
+//            System.setSecurityManager(new TopSecurityManager());
+//        } catch (SecurityException ex) {
+//            LOG.log(Level.WARNING, "Cannot associated own security manager"); // NOI18N
+//            LOG.log(Level.INFO, "Cannot associated own security manager", ex); // NOI18N
+//        }
     }
     static void uninstall() {
-        System.setSecurityManager(null);
+        // sec man is deprecated
+//        System.setSecurityManager(null);
     }
     
     /** Prohibits to set another SecurityManager */

@neilcsmith-net
Copy link
Member

This is a known issue that needs to be resolved for NetBeans 25. See #3386 and #7928 for options under consideration.

NetBeans 24 will not support running on JDK 24. You might be able to remove the option in the launcher and just pass the system property to disable the security manager - shouldn't need to recompile, for Linux and macOS at least.

@neilcsmith-net neilcsmith-net added needs:discussion Requires discussion on the NetBeans dev mailing list and removed needs:triage Requires attention from one of the committers labels Nov 29, 2024
@homberghp
Copy link
Contributor Author

Issue no longer relevant.

Recent pull of NetBeans sources and subsequent build no longer has the issue.
Propose to close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix needs:discussion Requires discussion on the NetBeans dev mailing list
Projects
None yet
Development

No branches or pull requests

2 participants