From 6562015e61f61b66c61e3172d77fc6c84aae1fb5 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Wed, 18 Feb 2026 07:33:39 +0100 Subject: [PATCH] Use Runtime.version() where applicable and remove unreachable code - replace reflective access with direct calls - replace java version parsing with Runtime.version() - remove dead code paths due to past JDK bumps - minor cleanup in touched files --- .../GradleJavaCompatProblemsProvider.java | 7 +- .../execute/DefaultJavaRuntimeManager.java | 2 +- .../ui/views/debugging/DebugTreeView.java | 9 +- .../jpda/ui/models/BigStringCustomEditor.java | 30 +-- .../debugger/jpda/expr/EvaluatorVisitor.java | 2 +- .../modules/debugger/jpda/util/JPDAUtils.java | 17 +- .../file/launcher/SingleSourceFileUtil.java | 7 +- .../errors/EnablePreviewSingleSourceFile.java | 13 +- .../EnablePreviewSingleSourceFile.java | 9 +- java/java.source.base/nbproject/project.xml | 8 - .../modules/java/source/NoJavacHelper.java | 60 ------ .../utilities/CommonUtilities.java | 14 -- .../project/connections/ftp/FtpClient.java | 15 -- .../ftp/WindowsJdk7WarningPanel.form | 123 ------------- .../ftp/WindowsJdk7WarningPanel.java | 171 ------------------ .../nativeaccess/NativeWindowSystemImpl.java | 15 -- .../org/netbeans/core/output2/Controller.java | 18 +- .../core/windows/options/WinSysPanel.java | 23 +-- .../view/ui/CloseButtonTabbedPane.java | 22 --- .../modules/netbinox/JarBundleFile.java | 15 +- .../modules/netbinox/NetbinoxFactory.java | 25 +-- .../src/org/netbeans/JarClassLoader.java | 62 ++----- .../src/org/netbeans/swing/plaf/Startup.java | 17 +- 23 files changed, 43 insertions(+), 641 deletions(-) delete mode 100644 php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.form delete mode 100644 php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.java diff --git a/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java b/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java index 98fe3addd227..815dc8576c9f 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/GradleJavaCompatProblemsProvider.java @@ -118,12 +118,7 @@ private int getJavaVersion() { } if (javaHome == null) { - String javaVersion = System.getProperty("java.specification.version"); - int dot = javaVersion.indexOf('.'); - if (dot > 0) { - javaVersion = javaVersion.substring(0, dot); - } - return Integer.parseInt(javaVersion); + return Runtime.version().feature(); } else { return getJavaMajorVersion(javaHome); } diff --git a/extide/gradle/src/org/netbeans/modules/gradle/execute/DefaultJavaRuntimeManager.java b/extide/gradle/src/org/netbeans/modules/gradle/execute/DefaultJavaRuntimeManager.java index dad0aacb1796..b43bdbdd370e 100644 --- a/extide/gradle/src/org/netbeans/modules/gradle/execute/DefaultJavaRuntimeManager.java +++ b/extide/gradle/src/org/netbeans/modules/gradle/execute/DefaultJavaRuntimeManager.java @@ -40,7 +40,7 @@ public class DefaultJavaRuntimeManager implements JavaRuntimeManager { }) public DefaultJavaRuntimeManager() { File javaHome = new File(System.getProperty("java.home")); //NOI18N - String javaVersion = System.getProperty("java.specification.version"); //NOI18N + int javaVersion = Runtime.version().feature(); JavaRuntime defaultRuntime = JavaRuntimeManager.createJavaRuntime(DEFAULT_RUNTIME_ID, Bundle.DEFAULT_JAVA_RUNTIME_NAME(javaVersion), javaHome); defaultRuntimes = Collections.singletonMap(DEFAULT_RUNTIME_ID, defaultRuntime); diff --git a/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/debugging/DebugTreeView.java b/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/debugging/DebugTreeView.java index f034f56e58da..36a17fc76ab5 100644 --- a/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/debugging/DebugTreeView.java +++ b/ide/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/views/debugging/DebugTreeView.java @@ -113,13 +113,8 @@ public class DebugTreeView extends BeanTreeView { tree.setCellRenderer(rend); setBackground(tree.getBackground()); - if (System.getProperty("java.version").startsWith("1.6") && - "GTK".equals(UIManager.getLookAndFeel().getID())) { - // leave the tree as opaque to paint the whole area - } else { - tree.setOpaque(false); - ((JComponent)tree.getParent()).setOpaque(false); - } + tree.setOpaque(false); + ((JComponent)tree.getParent()).setOpaque(false); ((JComponent)tree.getParent()).setBackground(tree.getBackground()); setWheelScrollingEnabled(false); } diff --git a/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/BigStringCustomEditor.java b/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/BigStringCustomEditor.java index 7f02bd1cca2d..92783a0a5ed1 100644 --- a/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/BigStringCustomEditor.java +++ b/java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/BigStringCustomEditor.java @@ -39,7 +39,6 @@ import org.netbeans.modules.debugger.jpda.models.ShortenedStrings.StringInfo; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; -import org.openide.awt.Actions; import org.openide.awt.Mnemonics; import org.openide.filesystems.FileChooserBuilder; import org.openide.util.NbBundle; @@ -51,37 +50,10 @@ */ class BigStringCustomEditor extends JPanel implements ActionListener { - static final int MAX_STRING_LENGTH; + static final int MAX_STRING_LENGTH = AbstractObjectVariable.MAX_STRING_LENGTH; private final StringInfo shortenedInfo; private final String fullString; - - static { - int maxStringLength = AbstractObjectVariable.MAX_STRING_LENGTH; - String javaV = System.getProperty("java.version"); - if (javaV.startsWith("1.8.0")) { - String update = ""; - for (int i = "1.8.0_".length(); i < javaV.length(); i++) { - char c = javaV.charAt(i); - if (Character.isDigit(c)) { - update += c; - } else { - break; - } - } - int updateNo = 0; - if (!update.isEmpty()) { - try { - updateNo = Integer.parseInt(update); - } catch (NumberFormatException nfex) {} - } - if (updateNo < 60) { - // Memory problem on JDK 8, fixed in update 60 (https://bugs.openjdk.java.net/browse/JDK-8072775): - maxStringLength = 1000; - } - } - MAX_STRING_LENGTH = maxStringLength; - } private BigStringCustomEditor(Component delegateCustomEditor, StringInfo shortenedInfo, int preferredShortLength) { this.shortenedInfo = shortenedInfo; diff --git a/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java b/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java index 33e84be2e12b..a21c1b75626b 100644 --- a/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java +++ b/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/expr/EvaluatorVisitor.java @@ -445,7 +445,7 @@ public Mirror visitMethodInvocation(MethodInvocationTree arg0, EvaluationContext } else if (type instanceof ClassType) { cType = (ClassType) type; } else { - if (JPDAUtils.IS_JDK_180_40 && (type instanceof InterfaceType) && isStatic) { + if ((type instanceof InterfaceType) && isStatic) { cType = null; iType = (InterfaceType) type; } else { diff --git a/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/util/JPDAUtils.java b/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/util/JPDAUtils.java index 32c892743aff..207f5cdfe66b 100644 --- a/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/util/JPDAUtils.java +++ b/java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/util/JPDAUtils.java @@ -43,25 +43,10 @@ * @author Jan Jancura */ public class JPDAUtils { - private static final String JAVA_VERSION = System.getProperty("java.version"); /** * true when the current JDK version is 1.8.0 update 40, or newer. */ - public static final boolean IS_JDK_180_40 = !JAVA_VERSION.startsWith("1.8.0") || // we know that it's 1.8.0 at least - getVersionUpdate(JAVA_VERSION) >= 40; - - - private static int getVersionUpdate(String javaVersion) { - if (javaVersion.length() < 7) { - return 0; - } - String update = javaVersion.substring(6); - try { - return Integer.parseInt(update); - } catch (NumberFormatException nfex) { - return 0; - } - } + public static final boolean IS_JDK_180_40 = true; public static final ReferenceType getPreferredReferenceType(List referenceTypes, Logger logger) throws VMDisconnectedExceptionWrapper { ReferenceType preferredType; // The preferred reference type from the list diff --git a/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java b/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java index 662bfefb4ab6..06ce702f2612 100644 --- a/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java +++ b/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java @@ -54,12 +54,7 @@ public final class SingleSourceFileUtil { // TODO this checks the runtime JDK of NB! public static int findJavaVersion() throws NumberFormatException { // JEP-330 is supported only on JDK-11 and above. - String javaVersion = System.getProperty("java.specification.version"); //NOI18N - if (javaVersion.startsWith("1.")) { //NOI18N - javaVersion = javaVersion.substring(2); - } - int version = Integer.parseInt(javaVersion); - return version; + return Runtime.version().feature(); } public static final String GLOBAL_VM_OPTIONS = "java_file_launcher_global_vm_options"; //NOI18N diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/errors/EnablePreviewSingleSourceFile.java b/java/java.hints/src/org/netbeans/modules/java/hints/errors/EnablePreviewSingleSourceFile.java index b4f921e9dfb9..ad50f8f5f860 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/errors/EnablePreviewSingleSourceFile.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/errors/EnablePreviewSingleSourceFile.java @@ -49,7 +49,7 @@ public class EnablePreviewSingleSourceFile implements PreviewEnabler { private static final String FILE_VM_OPTIONS = "single_file_vm_options"; //NOI18N - private FileObject file; + private final FileObject file; private EnablePreviewSingleSourceFile(@NonNull FileObject file) { Parameters.notNull("file", file); //NOI18N @@ -68,7 +68,7 @@ public void enablePreview(String newSourceLevel) throws Exception { Matcher m = SOURCE_FLAG_PATTERN.matcher(compilerArgs); if (newSourceLevel == null) { - newSourceLevel = getJdkRunVersion(); + newSourceLevel = Integer.toString(Runtime.version().feature()); } if (compilerArgs.contains(SOURCE_FLAG)) { @@ -138,15 +138,6 @@ public Void run() throws IOException { } } - private static String getJdkRunVersion() { - String javaVersion = System.getProperty("java.specification.version"); //NOI18N - if (javaVersion.startsWith("1.")) { //NOI18N - javaVersion = javaVersion.substring(2); - } - - return javaVersion; - } - @ServiceProvider(service=Factory.class) public static final class FactoryImpl implements Factory { diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/EnablePreviewSingleSourceFile.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/EnablePreviewSingleSourceFile.java index 9cb55c7c1367..a23ba4cda8ca 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/EnablePreviewSingleSourceFile.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/EnablePreviewSingleSourceFile.java @@ -19,8 +19,6 @@ package org.netbeans.modules.java.lsp.server.singlesourcefile; import com.google.gson.JsonPrimitive; -import java.util.Collections; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.netbeans.api.annotations.common.NonNull; @@ -85,12 +83,7 @@ public void enablePreview(String newSourceLevel) throws Exception { } private static String getJdkRunVersion() { - String javaVersion = System.getProperty("java.specification.version"); //NOI18N - if (javaVersion.startsWith("1.")) { //NOI18N - javaVersion = javaVersion.substring(2); - } - - return javaVersion; + return Integer.toString(Runtime.version().feature()); } @ServiceProvider(service=Factory.class, position=10_000_000) diff --git a/java/java.source.base/nbproject/project.xml b/java/java.source.base/nbproject/project.xml index 47e43422d6d8..77962b63cee2 100644 --- a/java/java.source.base/nbproject/project.xml +++ b/java/java.source.base/nbproject/project.xml @@ -77,14 +77,6 @@ - - org.netbeans.libs.asm - - - - 5.4 - - org.netbeans.libs.javacapi diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java b/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java index d775035f06c9..4ed8c4b5fcc3 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/NoJavacHelper.java @@ -18,15 +18,7 @@ */ package org.netbeans.modules.java.source; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.security.ProtectionDomain; -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; /** * @@ -52,56 +44,4 @@ public static boolean hasWorkingJavac() { return HAS_WORKING_JAVAC; } - // safety net if someone manages to start NB on JDK 8 with nb-javac uninstalled - @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); - } - } - } } diff --git a/java/performance/src/org/netbeans/modules/performance/utilities/CommonUtilities.java b/java/performance/src/org/netbeans/modules/performance/utilities/CommonUtilities.java index 560a778c4d35..b26205a8047e 100644 --- a/java/performance/src/org/netbeans/modules/performance/utilities/CommonUtilities.java +++ b/java/performance/src/org/netbeans/modules/performance/utilities/CommonUtilities.java @@ -223,20 +223,6 @@ private static void closeToolbar(String menu){ mainWindow.pushKey(java.awt.event.KeyEvent.VK_ESCAPE); } } - - /** - * Work around issue 35962 (Main menu popup accidentally rolled up) - * Issue has been fixed for JDK 1.5, so we will use it only for JDK 1.4.X - */ - public static void workarroundMainMenuRolledUp() { - if(System.getProperty("java.version").indexOf("1.4") != -1) { - String helpMenu = Bundle.getStringTrimmed("org.netbeans.core.Bundle","Menu/Help") + "|" + Bundle.getStringTrimmed("org.netbeans.core.actions.Bundle" , "About"); - String about = Bundle.getStringTrimmed("org.netbeans.core.Bundle_nb", "CTL_About_Title"); - - new ActionNoBlock(helpMenu, null).perform(); - new NbDialogOperator(about).close(); - } - } public static String jEditProjectOpen() { diff --git a/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/FtpClient.java b/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/FtpClient.java index 3c67e9ffd5cb..aa8bc212ab16 100644 --- a/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/FtpClient.java +++ b/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/FtpClient.java @@ -230,7 +230,6 @@ public synchronized void connect() throws RemoteException { scheduleKeepAlive(); } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); if (ftpClient.isConnected()) { try { ftpClient.disconnect(); @@ -330,7 +329,6 @@ public synchronized String printWorkingDirectory() throws RemoteException { try { return printWorkingDirectoryInternal(); } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while pwd", ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotPwd", configuration.getHost()), ex, getReplyString()); } @@ -348,7 +346,6 @@ public synchronized boolean storeFile(String remote, InputStream local) throws R scheduleKeepAlive(); return fileStored; } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while storing file " + remote, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotStoreFile", remote), ex, getReplyString()); } @@ -361,7 +358,6 @@ public synchronized boolean deleteFile(String pathname) throws RemoteException { scheduleKeepAlive(); return fileDeleted; } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while deleting file " + pathname, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotDeleteFile", pathname), ex, getReplyString()); } @@ -374,7 +370,6 @@ public synchronized boolean deleteDirectory(String pathname) throws RemoteExcept scheduleKeepAlive(); return directoryDeleted; } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while deleting file " + pathname, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotDeleteFile", pathname), ex, getReplyString()); } @@ -387,7 +382,6 @@ public synchronized boolean rename(String from, String to) throws RemoteExceptio scheduleKeepAlive(); return fileRenamed; } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, String.format("Error while renaming file %s -> %s", from, to), ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotRenameFile", from, to), ex, getReplyString()); } @@ -411,7 +405,6 @@ public synchronized List listFiles() throws RemoteException { result.add(new RemoteFileImpl(f, pwd)); } } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while listing files for " + pwd, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotListFiles", pwd), ex, getReplyString()); } @@ -443,7 +436,6 @@ public synchronized RemoteFile listFile(String absolutePath) throws RemoteExcept } } } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while listing file for " + absolutePath, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotListFile", absolutePath), ex, getReplyString()); } @@ -458,7 +450,6 @@ public synchronized boolean retrieveFile(String remote, OutputStream local) thro scheduleKeepAlive(); return fileRetrieved; } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while retrieving file " + remote, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotStoreFile", remote), ex, getReplyString()); } @@ -469,7 +460,6 @@ public synchronized boolean changeWorkingDirectory(String pathname) throws Remot try { return ftpClient.changeWorkingDirectory(pathname); } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while changing directory " + pathname, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotChangeDirectory", pathname), ex, getReplyString()); } @@ -482,7 +472,6 @@ public synchronized boolean makeDirectory(String pathname) throws RemoteExceptio scheduleKeepAlive(); return directoryMade; } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while creating directory " + pathname, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotCreateDirectory", pathname), ex, getReplyString()); } @@ -494,7 +483,6 @@ public int getPermissions(String path) throws RemoteException { try { return getPermissions(getFile(path)); } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while getting permissions for " + path, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotGetPermissions", path), ex, getReplyString()); } @@ -505,7 +493,6 @@ public synchronized boolean setPermissions(int permissions, String path) throws try { return ftpClient.sendSiteCommand("chmod " + permissions + " " + path); // NOI18N } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); LOGGER.log(Level.FINE, "Error while setting permissions for " + path, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotSetPermissions", path), ex, getReplyString()); } @@ -525,7 +512,6 @@ public synchronized boolean exists(String parent, String name) throws RemoteExce scheduleKeepAlive(); return found; } catch (IOException ex) { - WindowsJdk7WarningPanel.warn(); String fullPath = parent + "/" + name; // NOI18N LOGGER.log(Level.FINE, "Error while checking existence of " + fullPath, ex); throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotCheckFileExistence", fullPath), ex, getReplyString()); @@ -618,7 +604,6 @@ synchronized void keepAlive() { LOGGER.log(Level.FINE, "Keep-alive (NOOP/PWD) error for " + configuration.getHost(), ex); keepAliveTask.cancel(); silentDisconnect(true); - WindowsJdk7WarningPanel.warn(); // #209043 - just inform user in the log, do not show any dialog if (io != null) { String message; diff --git a/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.form b/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.form deleted file mode 100644 index 99ec894bab75..000000000000 --- a/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.form +++ /dev/null @@ -1,123 +0,0 @@ - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.java b/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.java deleted file mode 100644 index 44779ba70534..000000000000 --- a/php/php.project/src/org/netbeans/modules/php/project/connections/ftp/WindowsJdk7WarningPanel.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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.modules.php.project.connections.ftp; - -import java.awt.Cursor; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.net.MalformedURLException; -import java.net.URL; -import javax.swing.GroupLayout; -import javax.swing.GroupLayout.Alignment; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextPane; -import javax.swing.LayoutStyle.ComponentPlacement; -import javax.swing.UIManager; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.awt.HtmlBrowser; -import org.openide.awt.Mnemonics; -import org.openide.util.Exceptions; -import org.openide.util.NbBundle; -import org.openide.util.Utilities; - -/** - * Warning about firewall issue on Windows and JDK 7, see issue #202021. - */ -public final class WindowsJdk7WarningPanel extends JPanel { - - private static final long serialVersionUID = 54654646872L; - - private static final boolean IS_WINDOWS = Utilities.isWindows(); - private static final boolean IS_JDK7 = System.getProperty("java.version").startsWith("1.7."); // NOI18N - - private static volatile Boolean windowsJdk7Warning; - - - private WindowsJdk7WarningPanel() { - initComponents(); - } - - /** - * Possibly open warning dialog. - */ - public static void warn() { - if (!showWindowsJdk7Warning()) { - return; - } - WindowsJdk7WarningPanel panel = new WindowsJdk7WarningPanel(); - NotifyDescriptor descriptor = new NotifyDescriptor.Message(panel, NotifyDescriptor.WARNING_MESSAGE); - DialogDisplayer.getDefault().notify(descriptor); - if (panel.doNotShowAgainCheckBox.isSelected()) { - hideWindowsJdk7Warning(); - } - } - - private static boolean showWindowsJdk7Warning() { - if (windowsJdk7Warning == null) { - windowsJdk7Warning = IS_WINDOWS && IS_JDK7 && FtpPreferences.getInstance().getWindowsJdk7Warning(); - } - return windowsJdk7Warning; - } - - private static void hideWindowsJdk7Warning() { - windowsJdk7Warning = false; - FtpPreferences.getInstance().setWindowsJdk7Warning(false); - } - - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - infoLabel = new JLabel(); - issueLinkLabel = new JLabel(); - doNotShowAgainCheckBox = new JCheckBox(); - infoScrollPane = new JScrollPane(); - infoTextPane = new JTextPane(); - - Mnemonics.setLocalizedText(infoLabel, NbBundle.getMessage(WindowsJdk7WarningPanel.class, "WindowsJdk7WarningPanel.infoLabel.text")); // NOI18N - Mnemonics.setLocalizedText(issueLinkLabel, NbBundle.getMessage(WindowsJdk7WarningPanel.class, "WindowsJdk7WarningPanel.issueLinkLabel.text")); - issueLinkLabel.addMouseListener(new MouseAdapter() { - public void mouseEntered(MouseEvent evt) { - issueLinkLabelMouseEntered(evt); - } - public void mousePressed(MouseEvent evt) { - issueLinkLabelMousePressed(evt); - } - }); - Mnemonics.setLocalizedText(doNotShowAgainCheckBox, NbBundle.getMessage(WindowsJdk7WarningPanel.class, "WindowsJdk7WarningPanel.doNotShowAgainCheckBox.text")); - - infoScrollPane.setBorder(null); - - infoTextPane.setBackground(UIManager.getDefaults().getColor("Label.background")); - infoTextPane.setBorder(null); - infoTextPane.setEditable(false); - infoTextPane.setText(NbBundle.getMessage(WindowsJdk7WarningPanel.class, "TXT_WinJdk7FtpWarning")); // NOI18N - infoScrollPane.setViewportView(infoTextPane); - - GroupLayout layout = new GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(Alignment.LEADING) - .addComponent(infoLabel) - .addComponent(doNotShowAgainCheckBox)) - .addContainerGap(116, Short.MAX_VALUE)) - .addComponent(infoScrollPane, GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addComponent(issueLinkLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(infoLabel) - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(infoScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addComponent(issueLinkLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(ComponentPlacement.RELATED, 16, Short.MAX_VALUE) - .addComponent(doNotShowAgainCheckBox)) - ); - }// //GEN-END:initComponents - - private void issueLinkLabelMouseEntered(MouseEvent evt) {//GEN-FIRST:event_issueLinkLabelMouseEntered - evt.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - }//GEN-LAST:event_issueLinkLabelMouseEntered - - private void issueLinkLabelMousePressed(MouseEvent evt) {//GEN-FIRST:event_issueLinkLabelMousePressed - try { - URL url = new URL("http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7077696"); // NOI18N - HtmlBrowser.URLDisplayer.getDefault().showURL(url); - } catch (MalformedURLException ex) { - Exceptions.printStackTrace(ex); - } - }//GEN-LAST:event_issueLinkLabelMousePressed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private JCheckBox doNotShowAgainCheckBox; - private JLabel infoLabel; - private JScrollPane infoScrollPane; - private JTextPane infoTextPane; - private JLabel issueLinkLabel; - // End of variables declaration//GEN-END:variables -} diff --git a/platform/core.nativeaccess/src/org/netbeans/core/nativeaccess/NativeWindowSystemImpl.java b/platform/core.nativeaccess/src/org/netbeans/core/nativeaccess/NativeWindowSystemImpl.java index 096743a62c2d..eccd46132123 100644 --- a/platform/core.nativeaccess/src/org/netbeans/core/nativeaccess/NativeWindowSystemImpl.java +++ b/platform/core.nativeaccess/src/org/netbeans/core/nativeaccess/NativeWindowSystemImpl.java @@ -31,8 +31,6 @@ import java.util.logging.Logger; import javax.swing.Icon; import org.netbeans.core.windows.nativeaccess.NativeWindowSystem; -import org.openide.util.Utilities; - /** * Implementation of NativeWindowSystem based on JNA library. @@ -49,16 +47,9 @@ public NativeWindowSystemImpl() { @Override public boolean isWindowAlphaSupported() { - if( Utilities.isMac() ) { - String version = System.getProperty("java.version"); //NOI18N - if( null != version && version.startsWith("1.7" ) ) //NOI18N - return false; - } boolean res = false; try { res = WindowUtils.isWindowAlphaSupported(); - } catch( ThreadDeath td ) { - throw td; } catch (UnsatisfiedLinkError e) { // E.g. "Unable to load library 'X11': libX11.so: cannot open shared object file: No such file or directory" // on headless build machine (missing libx11-dev.deb) @@ -89,8 +80,6 @@ public void setWindowAlpha(Window w, float alpha) { //try the JNA way try { WindowUtils.setWindowAlpha(w, alpha); - } catch( ThreadDeath td ) { - throw td; } catch( Throwable e ) { LOG.log(Level.INFO, null, e); } @@ -127,8 +116,6 @@ public void setWindowMask(Window w, Shape mask) { return; try { WindowUtils.setWindowMask(w, mask); - } catch( ThreadDeath td ) { - throw td; } catch( Throwable e ) { LOG.log(Level.INFO, null, e); } @@ -138,8 +125,6 @@ public void setWindowMask(Window w, Shape mask) { public void setWindowMask(Window w, Icon mask) { try { WindowUtils.setWindowMask(w, mask); - } catch( ThreadDeath td ) { - throw td; } catch( Throwable e ) { LOG.log(Level.INFO, null, e); } diff --git a/platform/core.output2/src/org/netbeans/core/output2/Controller.java b/platform/core.output2/src/org/netbeans/core/output2/Controller.java index ee692711d531..6e62909382fb 100644 --- a/platform/core.output2/src/org/netbeans/core/output2/Controller.java +++ b/platform/core.output2/src/org/netbeans/core/output2/Controller.java @@ -37,7 +37,6 @@ import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.SwingUtilities; -import javax.swing.UIManager; import javax.swing.text.Document; import org.netbeans.core.output2.options.OutputOptions; import org.openide.util.Exceptions; @@ -173,21 +172,6 @@ void updateName(OutputTab tab) { nameUpdater.add(tab); } - private static boolean htmlTabsBroken() { - String version = System.getProperty("java.version"); - for (int i = 14; i < 18; i++) { - if (version.startsWith("1.6.0_" + i)) { - return true; - } - } - if( version.startsWith("1.6.0") && "Aqua".equals( UIManager.getLookAndFeel().getID() ) ) - return true; - return false; - } - - // workaround for JDK bug (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6670274) - // NB issue #113388 - private static final boolean DONT_USE_HTML = htmlTabsBroken(); private CoalescedNameUpdater nameUpdater = null; /** * Calls to methods invoked on NbIO done on the EQ are invoked synchronously @@ -241,7 +225,7 @@ public void run() { escaped = io.getName(); } String name = io.isStreamClosed() ? io.getName() + " " : //NOI18N - (DONT_USE_HTML ? io.getName() + " * " : "" + escaped + "  "); //NOI18N + ("" + escaped + "  "); //NOI18N if (LOG) { log(" set name to " + name); diff --git a/platform/core.windows/src/org/netbeans/core/windows/options/WinSysPanel.java b/platform/core.windows/src/org/netbeans/core/windows/options/WinSysPanel.java index 3382f6d61fe4..773bf0336921 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/options/WinSysPanel.java +++ b/platform/core.windows/src/org/netbeans/core/windows/options/WinSysPanel.java @@ -21,7 +21,6 @@ import java.util.prefs.Preferences; import javax.swing.JPanel; -import org.netbeans.api.options.OptionsDisplayer; import org.netbeans.core.windows.FloatingWindowTransparencyManager; import org.netbeans.core.windows.nativeaccess.NativeWindowSystem; import org.netbeans.spi.options.OptionsPanelController; @@ -40,8 +39,7 @@ protected WinSysPanel(final WinSysOptionsPanelController controller) { this.controller = controller; initComponents(); // TODO listen to changes in form fields and call controller.changed() - boolean isMacJDK17 = isMacJDK7(); - this.isAlphaFloating.setEnabled(!isMacJDK17); + this.isAlphaFloating.setEnabled(true); } /** This method is called from within the constructor to @@ -156,9 +154,8 @@ private void isSnapScreenEdgesActionPerformed(java.awt.event.ActionEvent evt) {/ private void fireChanged() { boolean isChanged = false; boolean isNotSolaris = Utilities.getOperatingSystem() != Utilities.OS_SOLARIS; - boolean isMacJDK17 = isMacJDK7(); - if (isDragImage.isSelected() != prefs.getBoolean(WinSysPrefs.DND_DRAGIMAGE, isNotSolaris && !isMacJDK17) - || isDragImageAlpha.isSelected() != prefs.getBoolean(WinSysPrefs.TRANSPARENCY_DRAGIMAGE, isNotSolaris && !isMacJDK17) + if (isDragImage.isSelected() != prefs.getBoolean(WinSysPrefs.DND_DRAGIMAGE, isNotSolaris) + || isDragImageAlpha.isSelected() != prefs.getBoolean(WinSysPrefs.TRANSPARENCY_DRAGIMAGE, isNotSolaris) || isAlphaFloating.isSelected() != prefs.getBoolean(WinSysPrefs.TRANSPARENCY_FLOATING, false) || isSnapping.isSelected() != prefs.getBoolean(WinSysPrefs.SNAPPING, true) || isSnapScreenEdges.isSelected() != prefs.getBoolean(WinSysPrefs.SNAPPING_SCREENEDGES, true)) { @@ -169,9 +166,8 @@ private void fireChanged() { protected void load() { boolean isNotSolaris = Utilities.getOperatingSystem() != Utilities.OS_SOLARIS; - boolean isMacJDK17 = isMacJDK7(); - isDragImage.setSelected(prefs.getBoolean(WinSysPrefs.DND_DRAGIMAGE, isNotSolaris && !isMacJDK17)); - isDragImageAlpha.setSelected(prefs.getBoolean(WinSysPrefs.TRANSPARENCY_DRAGIMAGE, isNotSolaris && !isMacJDK17)); + isDragImage.setSelected(prefs.getBoolean(WinSysPrefs.DND_DRAGIMAGE, isNotSolaris)); + isDragImageAlpha.setSelected(prefs.getBoolean(WinSysPrefs.TRANSPARENCY_DRAGIMAGE, isNotSolaris)); isAlphaFloating.setSelected(prefs.getBoolean(WinSysPrefs.TRANSPARENCY_FLOATING,false)); @@ -233,15 +229,6 @@ private void updateFloatingSection () { NbBundle.getMessage(WinSysPanel.class, "NoAlphaSupport")); // NOI18N } } - - private static boolean isMacJDK7() { - if( Utilities.isMac() ) { - String version = System.getProperty("java.version"); //NOI18N - if( null != version && version.startsWith("1.7" ) ) //NOI18N - return true; - } - return false; - } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; diff --git a/platform/core.windows/src/org/netbeans/core/windows/view/ui/CloseButtonTabbedPane.java b/platform/core.windows/src/org/netbeans/core/windows/view/ui/CloseButtonTabbedPane.java index c36eb283f24d..84e2945ebbed 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/view/ui/CloseButtonTabbedPane.java +++ b/platform/core.windows/src/org/netbeans/core/windows/view/ui/CloseButtonTabbedPane.java @@ -30,7 +30,6 @@ import java.beans.PropertyChangeListener; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.regex.Pattern; import javax.swing.*; import javax.swing.plaf.UIResource; import org.netbeans.core.windows.actions.MaximizeWindowAction; @@ -239,33 +238,12 @@ public void removeTabAt(int index) { super.removeTabAt(index); } - private static final boolean HTML_TABS_BROKEN = htmlTabsBroken(); - private static boolean htmlTabsBroken() { - String version = System.getProperty("java.version"); - for (int i = 14; i < 18; i++) { - if (version.startsWith("1.6.0_" + i)) { - return true; - } - } - if( version.startsWith("1.6.0") && IS_AQUA_LAF ) - return true; - return false; - } - private final Pattern removeHtmlTags = HTML_TABS_BROKEN ? Pattern.compile("\\<.*?\\>") : null; - @Override public void setTitleAt(int idx, String title) { if (title == null) { super.setTitleAt(idx, null); return; } - // workaround for JDK bug (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6670274) - // NB issue #113388 - if (removeHtmlTags != null && title.startsWith("")) { - title = removeHtmlTags.matcher(title).replaceAll(""); - title = title.replace(" ", ""); - } - super.setTitleAt(idx, title); // Force update of the special "CloseButton" UI. It was observed, that // after a change to an empty title changing to a title with content diff --git a/platform/netbinox/src/org/netbeans/modules/netbinox/JarBundleFile.java b/platform/netbinox/src/org/netbeans/modules/netbinox/JarBundleFile.java index 077ccf2a8bfc..f026480182ef 100644 --- a/platform/netbinox/src/org/netbeans/modules/netbinox/JarBundleFile.java +++ b/platform/netbinox/src/org/netbeans/modules/netbinox/JarBundleFile.java @@ -61,20 +61,9 @@ final class JarBundleFile extends BundleFile implements BundleContent { private static final String META_INF = "META-INF/"; private static final Name MULTI_RELEASE = new Name("Multi-Release"); private static final int BASE_VERSION = 8; - private static final int RUNTIME_VERSION; + private static final int RUNTIME_VERSION = Runtime.version().feature(); private static Map usedIds; - static { - int version; - try { - Object runtimeVersion = Runtime.class.getMethod("version").invoke(null); - version = (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion); - } catch (ReflectiveOperationException ex) { - version = BASE_VERSION; - } - RUNTIME_VERSION = version; - } - private BundleFile delegate; private final MRUBundleFileList mru; @@ -100,7 +89,7 @@ final class JarBundleFile extends BundleFile implements BundleContent { assert assertOn = true; if (assertOn) { if (usedIds == null) { - usedIds = new HashMap(); + usedIds = new HashMap<>(); } File prev = usedIds.put(id, base); if (prev != null && !prev.equals(base)) { diff --git a/platform/netbinox/src/org/netbeans/modules/netbinox/NetbinoxFactory.java b/platform/netbinox/src/org/netbeans/modules/netbinox/NetbinoxFactory.java index e7e65f08f51e..dca9a23a3849 100644 --- a/platform/netbinox/src/org/netbeans/modules/netbinox/NetbinoxFactory.java +++ b/platform/netbinox/src/org/netbeans/modules/netbinox/NetbinoxFactory.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; import org.eclipse.osgi.launch.EquinoxFactory; import org.netbeans.core.netigso.spi.NetigsoArchive; import org.openide.util.Utilities; @@ -50,7 +49,7 @@ public class NetbinoxFactory implements FrameworkFactory { @Override @SuppressWarnings("unchecked") public Framework newFramework(Map map) { - Map configMap = new HashMap(); + Map configMap = new HashMap<>(32); configMap.putAll(map); // configMap.put("osgi.hook.configurators.exclude", // NOI18N // "org.eclipse.core.runtime.internal.adaptor.EclipseLogHook" // NOI18N @@ -80,20 +79,9 @@ public Framework newFramework(Map map) { // Ensure that the org.osgi.framework.executionenvironment holds all // JavaSE entries that match till the current JDK. The dynamic approach // will work also for newly released JDKs. - Integer javaSpecificationMajorVersion = null; - try { - // java >= 9 - Object runtimeVersion = Runtime.class.getMethod("version").invoke(null); - javaSpecificationMajorVersion = (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion); - } catch (ReflectiveOperationException ignore) { - // java < 9 - LOG.log( - Level.FINE, - "Failed to invoke Runtime#version or Runtime.Version#major to determine JavaSE major version", - ignore - ); - } - if(javaSpecificationMajorVersion != null && javaSpecificationMajorVersion > 8) { + int javaSpecificationMajorVersion = Runtime.version().feature(); + + if (javaSpecificationMajorVersion > 8) { List values = new ArrayList<>(); values.add("OSGi/Minimum-1.0"); values.add("OSGi/Minimum-1.1"); @@ -112,10 +100,7 @@ public Framework newFramework(Map map) { for (int i = 9; i <= javaSpecificationMajorVersion; i++) { values.add("JavaSE-" + i); } - configMap.put( - "org.osgi.framework.executionenvironment", - values.stream().collect(Collectors.joining(", ")) - ); + configMap.put("org.osgi.framework.executionenvironment", String.join(", ", values)); } Object rawBundleMap = configMap.get("felix.bootdelegation.classloaders"); // NOI18N diff --git a/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java b/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java index dd524401e249..ef998f05a104 100644 --- a/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java +++ b/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java @@ -30,7 +30,6 @@ import java.lang.instrument.IllegalClassFormatException; import java.lang.ref.Reference; import java.lang.ref.SoftReference; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.JarURLConnection; import java.net.MalformedURLException; @@ -90,18 +89,7 @@ public class JarClassLoader extends ProxyClassLoader { private static final String META_INF = "META-INF/"; private static final Name MULTI_RELEASE = new Name("Multi-Release"); private static final int BASE_VERSION = 8; - private static final int RUNTIME_VERSION; - - static { - int version; - try { - Object runtimeVersion = Runtime.class.getMethod("version").invoke(null); - version = (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion); - } catch (ReflectiveOperationException ex) { - version = BASE_VERSION; - } - RUNTIME_VERSION = version; - } + private static final int RUNTIME_VERSION = Runtime.version().feature(); static Archive archive = new Archive(); @@ -173,7 +161,7 @@ public JarClassLoader(List files, ClassLoader[] parents, boolean transitiv } catch (IOException exc) { throw new IllegalArgumentException(exc.getMessage()); } - sources = l.toArray(new Source[0]); + sources = l.toArray(Source[]::new); // overlaps with old packages doesn't matter,PCL uses sets. addCoveredPackages(getCoveredPackages(module, sources)); } @@ -186,7 +174,7 @@ final void addURL(URL location) throws IOException, URISyntaxException { arr.add(new JarSource(f)); synchronized (sources) { - sources = arr.toArray(new Source[0]); + sources = arr.toArray(Source[]::new); } // overlaps with old packages doesn't matter,PCL uses sets. @@ -352,8 +340,8 @@ public Enumeration findResources(String name) { * Used from JarClassLoaderTest to force close before reopening. */ void releaseJars() throws IOException { for (Source src : sources) { - if (src instanceof JarSource) { - ((JarSource)src).doCloseJar(); + if (src instanceof JarSource jarSource) { + jarSource.doCloseJar(); } } } @@ -793,20 +781,8 @@ protected void destroy() throws IOException { File temp = Files.createTempFile(prefix, suffix).toFile(); temp.deleteOnExit(); - InputStream is = new FileInputStream(orig); - try { - OutputStream os = new FileOutputStream(temp); - try { - byte[] buf = new byte[4096]; - int j; - while ((j = is.read(buf)) != -1) { - os.write(buf, 0, j); - } - } finally { - os.close(); - } - } finally { - is.close(); + try (InputStream is = new FileInputStream(orig); OutputStream os = new FileOutputStream(temp)) { + is.transferTo(os); } doCloseJar(); @@ -828,12 +804,10 @@ private JarFile callGet() throws IOException { interrupted = true; } catch (ExecutionException ex) { Throwable cause = ex.getCause(); - if (cause instanceof IOException) { + if (cause instanceof IOException ioe) { // This is important for telling general IOException from ZipException // down the stack. - throw (IOException)cause; - } else if (cause instanceof ThreadDeath) { - throw (ThreadDeath) cause; // #201098 + throw ioe; } else { throw new IOException(cause); } @@ -966,33 +940,28 @@ public Manifest getManifest() { return manifest = mf; } + @Override public String getPath() { return dir.getPath(); } + @Override protected URL doGetResource(String name) throws MalformedURLException { File resFile = new File(dir, name); return resFile.exists() ? BaseUtilities.toURI(resFile).toURL() : null; } + @Override protected byte[] readClass(String path) throws IOException { File clsFile = new File(dir, path.replace('/', File.separatorChar)); if (!clsFile.exists()) return null; - int len = (int)clsFile.length(); - byte[] data = new byte[len]; - InputStream is = new FileInputStream(clsFile); - try { - int count = 0; - while (count < len) { - count += is.read(data, count, len - count); - } - return data; - } finally { - is.close(); + try (InputStream is = new FileInputStream(clsFile)) { + return is.readAllBytes(); } } + @Override protected void listCoveredPackages(Set known, StringBuffer save) { appendAllChildren(known, save, dir, ""); } @@ -1178,6 +1147,7 @@ private boolean isFolder() { return name.length() == 0 || name.endsWith("/"); } + @Override public void connect() throws IOException { if (isFolder()) { return; // #139087: odd but harmless diff --git a/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java b/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java index 13fff7090c67..30c2bb7f5e58 100644 --- a/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java +++ b/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/Startup.java @@ -181,20 +181,9 @@ private static String defaultLaF() { } else { //Should get us metal where it doesn't get us GTK uiClassName = UIManager.getSystemLookAndFeelClassName(); - // Enable GTK L&F only for JDK version 1.6.0 update 1 and later. - // GTK L&F quality unacceptable for earlier versions. - // Also enable GTK L&F for OpenJDK - String javaVersion = System.getProperty("java.version"); - if ("1.6.0_01".compareTo(javaVersion) > 0 && System.getProperty("java.vm.name") != null && System.getProperty("java.vm.name").indexOf("OpenJDK") < 0) { - // IDE runs on 1.5 or 1.6 - useGtk can enabled Gtk - if (uiClassName.indexOf("gtk") >= 0 && !Boolean.getBoolean("useGtk")) { - uiClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; - } - } else { - // IDE runs on 1.6_0_01 or higher - useGtk can disabled Gtk - if (uiClassName.indexOf("gtk") >= 0 && System.getProperty("useGtk") != null && !Boolean.getBoolean("useGtk")) { - uiClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; - } + // useGtk can disabled Gtk + if (uiClassName.indexOf("gtk") >= 0 && System.getProperty("useGtk") != null && !Boolean.getBoolean("useGtk")) { + uiClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; } // #118534 - don't allow Nimbus L&F as default system L&F, // as we're not ready to support it yet