Skip to content

Commit

Permalink
Merge pull request AdoptOpenJDK#546 from AdoptOpenJDK/cleanupJnpClass…
Browse files Browse the repository at this point in the history
…loader

Cleanup jnp classloader
  • Loading branch information
sclassen authored Dec 12, 2019
2 parents 3b5c87e + ec2067e commit 72b3042
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.adoptopenjdk.icedteaweb;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static net.adoptopenjdk.icedteaweb.CollectionUtils.isNullOrEmpty;

public class StringUtils {

Expand Down Expand Up @@ -90,7 +90,7 @@ public static List<String> splitIntoMultipleLines(final String s, final int maxC
public static boolean hasPrefixMatch(final String prefixString, final String[] available) {
Assert.requireNonBlank(prefixString, "prefixString");

if (available == null || available.length == 0){
if (isNullOrEmpty(available)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import java.util.Date;
import java.util.List;

import static net.sourceforge.jnlp.LaunchException.FATAL;

public class UnsignedAppletTrustConfirmation {

private final static Logger LOG = LoggerFactory.getLogger(UnsignedAppletTrustConfirmation.class);
Expand Down Expand Up @@ -201,7 +203,7 @@ public static void checkUnsignedWithUserIfRequired(JNLPFile file) throws LaunchE

if (unsignedAppletsAreForbidden()) {
LOG.debug("Not running unsigned applet at {} because unsigned applets are disallowed by security policy.", file.getCodeBase());
throw new LaunchException(file, null, "Fatal", "Application Error", "The applet was unsigned.", "The applet was unsigned.PolicyDenied");
throw new LaunchException(file, null, FATAL, "Application Error", "The applet was unsigned.", "The applet was unsigned.PolicyDenied");
}

if (!unsignedConfirmationIsRequired()) {
Expand All @@ -214,7 +216,7 @@ public static void checkUnsignedWithUserIfRequired(JNLPFile file) throws LaunchE
LOG.debug("Decided action for unsigned applet at {} was {}", file.getCodeBase(), warningResponse);

if (warningResponse == null || !warningResponse.compareValue(Primitive.YES)) {
throw new LaunchException(file, null, "Fatal", "Application Error", "The applet was unsigned.", "The applet was unsigned.UserDenied");
throw new LaunchException(file, null, FATAL, "Application Error", "The applet was unsigned.", "The applet was unsigned.UserDenied");
}

}
Expand All @@ -232,7 +234,7 @@ public static void checkPartiallySignedWithUserIfRequired(SecurityDelegate secur
LOG.debug("Decided action for unsigned applet at {} was {}", file.getCodeBase(), warningResponse);

if (warningResponse == null || warningResponse.compareValue(Primitive.NO)) {
throw new LaunchException(file, null, "Fatal", "Application Error", "The applet was partially signed.", "The applet was partially signed.UserDenied");
throw new LaunchException(file, null, FATAL, "Application Error", "The applet was partially signed.", "The applet was partially signed.UserDenied");
}

//this is due to possible YesNoSandboxLimited
Expand Down
13 changes: 7 additions & 6 deletions core/src/main/java/net/sourceforge/jnlp/JNLPFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.sourceforge.jnlp;

import net.adoptopenjdk.icedteaweb.CollectionUtils;
import net.adoptopenjdk.icedteaweb.IcedTeaWebConstants;
import net.adoptopenjdk.icedteaweb.JavaSystemProperties;
import net.adoptopenjdk.icedteaweb.StringUtils;
Expand Down Expand Up @@ -45,7 +46,6 @@
import net.adoptopenjdk.icedteaweb.xmlparser.XMLParser;
import net.adoptopenjdk.icedteaweb.xmlparser.XmlParserFactory;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.util.LocaleUtils;
import net.sourceforge.jnlp.util.LocaleUtils.Match;
import net.sourceforge.jnlp.util.UrlUtils;
import sun.net.www.protocol.http.HttpURLConnection;
Expand All @@ -64,10 +64,13 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import static net.adoptopenjdk.icedteaweb.CollectionUtils.isNullOrEmpty;
import static net.adoptopenjdk.icedteaweb.JavaSystemPropertiesConstants.HTTP_AGENT;
import static net.adoptopenjdk.icedteaweb.StringUtils.hasPrefixMatch;
import static net.sourceforge.jnlp.util.LocaleUtils.localMatches;
import static net.sourceforge.jnlp.util.LocaleUtils.localeMatches;
import static net.sourceforge.jnlp.util.UrlUtils.FILE_PROTOCOL;

/**
Expand Down Expand Up @@ -692,10 +695,8 @@ public <T> List<T> getResources(Class<T> launchType) {
List<T> result = new ArrayList<>();

for (ResourcesDesc rescDesc : resources) {
boolean hasUsableLocale = false;
for (final Match match : Match.values()) {
hasUsableLocale |= LocaleUtils.localeMatches(locale, rescDesc.getLocales(), match);
}
final Locale[] locales = rescDesc.getLocales();
final boolean hasUsableLocale = Stream.of(Match.values()).anyMatch(match -> localeMatches(locale, locales, match));
if (hasUsableLocale
&& hasPrefixMatch(os, rescDesc.getOS())
&& hasPrefixMatch(arch, rescDesc.getArch())) {
Expand Down Expand Up @@ -740,7 +741,7 @@ public ResourcesDesc[] getResourcesDescs(final Locale locale, final String os, f
for (ResourcesDesc rescDesc : resources) {
boolean hasUsableLocale = false;
for (Match match : Match.values()) {
hasUsableLocale |= LocaleUtils.localeMatches(locale, rescDesc.getLocales(), match);
hasUsableLocale |= localeMatches(locale, rescDesc.getLocales(), match);
}
if (hasUsableLocale
&& hasPrefixMatch(os, rescDesc.getOS())
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/net/sourceforge/jnlp/LaunchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
public class LaunchException extends Exception {


public static final String MINOR = "Minor";
public static final String SEVERE = "Severe";
public static final String FATAL = "Fatal";

public static class LaunchExceptionWithStamp{
private final LaunchException ex;
private final Date stamp;
Expand Down
30 changes: 16 additions & 14 deletions core/src/main/java/net/sourceforge/jnlp/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import java.util.Map;

import static net.adoptopenjdk.icedteaweb.i18n.Translator.R;
import static net.sourceforge.jnlp.LaunchException.FATAL;
import static net.sourceforge.jnlp.LaunchException.MINOR;
import static net.sourceforge.jnlp.util.UrlUtils.FILE_PROTOCOL;

/**
Expand Down Expand Up @@ -159,7 +161,7 @@ public ApplicationInstance launch(JNLPFile file, Container cont) throws LaunchEx
} catch (InterruptedException ex) {
//By default, null is thrown here, and the message dialog is shown.
if (handler != null) {
handler.handleLaunchWarning(new LaunchException(file, ex, "Minor", "System Error", "Thread interrupted while waiting for file to launch.", "This can lead to deadlock or yield other damage during execution. Please restart your application/browser."));
handler.handleLaunchWarning(new LaunchException(file, ex, MINOR, "System Error", "Thread interrupted while waiting for file to launch.", "This can lead to deadlock or yield other damage during execution. Please restart your application/browser."));
}
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -283,9 +285,9 @@ private void launchExternal(final JNLPFile file, final List<String> javawsArgs)
final JvmLauncher jvmLauncher = JNLPRuntime.getExtensionPoint().createJvmLauncher(config);
jvmLauncher.launchExternal(file, javawsArgs);
} catch (NullPointerException ex) {
throw launchError(new LaunchException(null, ex, "Fatal", "External Launch Error", "Could not determine location of javaws.jar.", "An attempt was made to launch a JNLP file in another JVM, but the javaws.jar could not be located. In order to launch in an external JVM, the runtime must be able to locate the javaws.jar file."));
throw launchError(new LaunchException(null, ex, FATAL, "External Launch Error", "Could not determine location of javaws.jar.", "An attempt was made to launch a JNLP file in another JVM, but the javaws.jar could not be located. In order to launch in an external JVM, the runtime must be able to locate the javaws.jar file."));
} catch (Exception ex) {
throw launchError(new LaunchException(null, ex, "Fatal", "External Launch Error", "Could not launch JNLP file.", "The application has not been initialized, for more information execute javaws/browser from the command line and send a bug report."));
throw launchError(new LaunchException(null, ex, FATAL, "External Launch Error", "Could not launch JNLP file.", "The application has not been initialized, for more information execute javaws/browser from the command line and send a bug report."));
}
}

Expand Down Expand Up @@ -326,7 +328,7 @@ private JNLPFile fromUrl(URL location) throws LaunchException {
}
return file;
} catch (Exception ex) {
throw launchError(new LaunchException(null, ex, "Fatal", "Read Error", "Could not read or parse the JNLP file.", "You can try to download this file manually and send it as bug report to IcedTea-Web team."));
throw launchError(new LaunchException(null, ex, FATAL, "Read Error", "Could not read or parse the JNLP file.", "You can try to download this file manually and send it as bug report to IcedTea-Web team."));
}
}

Expand All @@ -339,7 +341,7 @@ private JNLPFile fromUrl(URL location) throws LaunchException {
*/
private ApplicationInstance launchApplication(final JNLPFile file) throws LaunchException {
if (!file.isApplication()) {
throw launchError(new LaunchException(file, null, "Fatal", "Application Error", "Not an application file.", "An attempt was made to load a non-application file as an application."));
throw launchError(new LaunchException(file, null, FATAL, "Application Error", "Not an application file.", "An attempt was made to load a non-application file as an application."));
}

try {
Expand Down Expand Up @@ -386,7 +388,7 @@ private ApplicationInstance launchApplication(final JNLPFile file) throws Launch

if (mainName == null) {
throw launchError(new LaunchException(file, null,
"Fatal", "Application Error", "Unknown Main-Class.",
FATAL, "Application Error", "Unknown Main-Class.",
"Could not determine the main class for this application."));
}

Expand Down Expand Up @@ -414,7 +416,7 @@ private ApplicationInstance launchApplication(final JNLPFile file) throws Launch
} catch (LaunchException lex) {
throw launchError(lex);
} catch (Exception ex) {
throw launchError(new LaunchException(file, ex, "Fatal", "Launch Error", "Could not launch JNLP file.", "The application has not been initialized, for more information execute javaws/browser from the command line and send a bug report."));
throw launchError(new LaunchException(file, ex, FATAL, "Launch Error", "Could not launch JNLP file.", "The application has not been initialized, for more information execute javaws/browser from the command line and send a bug report."));
}
}

Expand Down Expand Up @@ -468,7 +470,7 @@ private void setContextClassLoaderForAllThreads(ThreadGroup tg, ClassLoader clas
*/
private ApplicationInstance launchApplet(final JNLPFile file, final Container cont) throws LaunchException {
if (!file.isApplet()) {
throw launchError(new LaunchException(file, null, "Fatal", "Application Error", "Not an applet file.", "An attempt was made to load a non-applet file as an applet."));
throw launchError(new LaunchException(file, null, FATAL, "Application Error", "Not an applet file.", "An attempt was made to load a non-applet file as an applet."));
}

if (JNLPRuntime.getForksStrategy().needsToFork(file)) {
Expand All @@ -492,11 +494,11 @@ private ApplicationInstance launchApplet(final JNLPFile file, final Container co
return applet;
} catch (InstanceExistsException ieex) {
LOG.error("Single instance applet is already running.", ieex);
throw launchError(new LaunchException(file, ieex, "Fatal", "Launch Error", "Could not launch JNLP file.", "Another instance of this applet already exists and only one may be run at the same time."));
throw launchError(new LaunchException(file, ieex, FATAL, "Launch Error", "Could not launch JNLP file.", "Another instance of this applet already exists and only one may be run at the same time."));
} catch (LaunchException lex) {
throw launchError(lex);
} catch (Exception ex) {
throw launchError(new LaunchException(file, ex, "Fatal", "Launch Error", "Could not launch JNLP file.", "The application has not been initialized, for more information execute javaws/browser from the command line and send a bug report."));
throw launchError(new LaunchException(file, ex, FATAL, "Launch Error", "Could not launch JNLP file.", "The application has not been initialized, for more information execute javaws/browser from the command line and send a bug report."));
}finally{
if (handler != null) {
handler.launchStarting(applet);
Expand All @@ -514,7 +516,7 @@ private ApplicationInstance launchApplet(final JNLPFile file, final Container co
private ApplicationInstance launchInstaller(final JNLPFile file) throws LaunchException {
// TODO Check for an existing single instance once implemented.
// ServiceUtil.checkExistingSingleInstance(file);
throw launchError(new LaunchException(file, null, "Fatal", "Unsupported Feature", "Installers not supported.", "JNLP installer files are not yet supported."));
throw launchError(new LaunchException(file, null, FATAL, "Unsupported Feature", "Installers not supported.", "JNLP installer files are not yet supported."));
}

/**
Expand Down Expand Up @@ -570,7 +572,7 @@ private AppletInstance createApplet(final JNLPFile file, final Container cont) t

return appletInstance;
} catch (Exception ex) {
throw launchError(new LaunchException(file, ex, "Fatal", "Initialization Error", "Could not initialize applet.", "For more information click \"more information button\"."));
throw launchError(new LaunchException(file, ex, FATAL, "Initialization Error", "Could not initialize applet.", "For more information click \"more information button\"."));
}
}

Expand All @@ -590,7 +592,7 @@ private ApplicationInstance createApplication(final JNLPFile file) throws Launch

return app;
} catch (Exception ex) {
throw new LaunchException(file, ex, "Fatal", "Initialization Error", "Could not initialize application.", "The application has not been initialized, for more information execute javaws from the command line.");
throw new LaunchException(file, ex, FATAL, "Initialization Error", "Could not initialize application.", "The application has not been initialized, for more information execute javaws from the command line.");
}
}

Expand Down Expand Up @@ -668,7 +670,7 @@ else if (file.isInstaller()) {
}
else {
throw launchError(new LaunchException(file, null,
"Fatal", "Application Error", "Not a launchable JNLP file.",
FATAL, "Application Error", "Not a launchable JNLP file.",
"File must be a JNLP application, applet, or installer type."));
}
} catch (LaunchException ex) {
Expand Down
Loading

0 comments on commit 72b3042

Please sign in to comment.