Skip to content

Commit 0e6a7ac

Browse files
committed
avoid comparing URLs using equals
1 parent d852263 commit 0e6a7ac

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/browser/HtmlBrowserPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private void put(URL url, List<URL> where) {
178178
if (url != null) {
179179
if (where.isEmpty()) {
180180
where.add(0, url);
181-
} else if (!where.get(0).equals(url)) {
181+
} else if (!where.get(0).toString().equals(url.toString())) {
182182
where.add(0, url);
183183
}
184184
}

core/src/main/java/net/adoptopenjdk/icedteaweb/resources/cache/CacheIndexEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ long getLastAccessed() {
5050
}
5151

5252
boolean matches(URL resource) {
53-
return key.getLocation().equals(resource);
53+
return key.matches(resource);
5454
}
5555

5656
boolean matches(CacheKey key) {

core/src/main/java/net/adoptopenjdk/icedteaweb/resources/cache/CacheKey.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ public boolean equals(final Object o) {
4747
public int hashCode() {
4848
return Objects.hash(locationString, version);
4949
}
50+
51+
public boolean matches(URL resource) {
52+
return resource != null && locationString.equals(resource.toString());
53+
}
5054
}

core/src/main/java/net/sourceforge/jnlp/Launcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private JNLPFile fromUrl(URL location) throws LaunchException {
309309
}
310310
if (!isLocal && haveHref) {
311311
//this is case when remote file have href to different file
312-
if (!location.equals(file.getSourceLocation())) {
312+
if (file.getSourceLocation() == null || !location.toString().equals(file.getSourceLocation().toString())) {
313313
//mark local true, so the following condition will be true and
314314
//new jnlp file will be downloaded
315315
isLocal = true;

core/src/main/java/net/sourceforge/jnlp/runtime/classloader/JNLPClassLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ private static JNLPClassLoader getInstance(JNLPFile file, UpdatePolicy policy, S
490490
// for this codebase/jnlp yet. Create one.
491491
if (baseLoader == null
492492
|| (file.isApplication()
493-
&& !baseLoader.getJNLPFile().getFileLocation().equals(file.getFileLocation()))) {
493+
&& (file.getFileLocation() == null || !baseLoader.getJNLPFile().getFileLocation().toString().equals(file.getFileLocation().toString())))) {
494494

495495
loader = createInstance(file, policy, mainName, enableCodeBase);
496496
} else {
@@ -536,7 +536,7 @@ private static JNLPClassLoader getInstance(final URL location, final String uniq
536536
synchronized (getUniqueKeyLock(uniqueKey)) {
537537
loader = uniqueKeyToLoader.get(uniqueKey);
538538

539-
if (loader == null || !location.equals(loader.getJNLPFile().getFileLocation())) {
539+
if (loader == null || loader.getJNLPFile().getFileLocation() == null || !location.toString().equals(loader.getJNLPFile().getFileLocation().toString())) {
540540
final JNLPFile jnlpFile = new JNLPFileFactory().create(location, uniqueKey, version, settings, policy);
541541

542542
loader = getInstance(jnlpFile, policy, mainName, enableCodeBase);

core/src/main/java/net/sourceforge/jnlp/runtime/classloader/LocateJnlpClassLoader.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ class LocateJnlpClassLoader {
5252
*/
5353
static JNLPClassLoader getLoaderByJnlpFile(final JNLPClassLoader rootClassLoader, URL urlToJnlpFile) {
5454

55-
if (rootClassLoader == null)
55+
if (rootClassLoader == null) {
5656
return null;
57+
}
5758

5859
JNLPFile file = rootClassLoader.getJNLPFile();
5960

60-
if (urlToJnlpFile == null)
61+
if (urlToJnlpFile == null) {
6162
urlToJnlpFile = rootClassLoader.getJNLPFile().getFileLocation();
62-
63-
if (file.getFileLocation().equals(urlToJnlpFile))
63+
} else if (file.getFileLocation().toString().equals(urlToJnlpFile.toString())) {
6464
return rootClassLoader;
65+
}
6566

6667
for (JNLPClassLoader loader : rootClassLoader.getLoaders()) {
6768
if (rootClassLoader != loader) {
@@ -89,7 +90,8 @@ static JNLPClassLoader getLoaderByResourceUrl(final JNLPClassLoader rootClassLoa
8990
ResourcesDesc resources = loader.getJNLPFile().getResources();
9091

9192
for (JARDesc eachJar : resources.getJARs()) {
92-
if (ref.equals(eachJar.getLocation()) &&
93+
if (eachJar.getLocation() != null &&
94+
ref.toString().equals(eachJar.getLocation().toString()) &&
9395
(resourceVersion == null || resourceVersion.equals(eachJar.getVersion())))
9496
return loader;
9597
}

core/src/test/java/net/adoptopenjdk/icedteaweb/resources/ResourceTrackerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public void testNormalizeUrl() throws Exception {
8282
Assert.assertNull("first url should be null", u[0]);
8383
Assert.assertNull("first normalized url should be null", n[0]);
8484
for (int i = 1; i < CHANGE_BORDER; i++) {
85-
Assert.assertTrue("url " + i + " must be equals too normalized url " + i, u[i].equals(n[i]));
85+
Assert.assertTrue("url " + i + " must be equals too normalized url " + i, u[i].toString().equals(n[i].toString()));
8686
}
8787
for (int i = CHANGE_BORDER; i < n.length; i++) {
88-
Assert.assertFalse("url " + i + " must be normalized (and so not equals) too normalized url " + i, u[i].equals(n[i]));
88+
Assert.assertFalse("url " + i + " must be normalized (and so not equals) too normalized url " + i, u[i].toString().equals(n[i].toString()));
8989
}
9090
}
9191

0 commit comments

Comments
 (0)