Skip to content

Commit 831bc2a

Browse files
authored
Merge pull request #906 from AdoptOpenJDK/improve-cache-key
Improve cache key
2 parents 4c11ffc + 0e6a7ac commit 831bc2a

File tree

8 files changed

+27
-15
lines changed

8 files changed

+27
-15
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/CacheImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ boolean isCached(CacheKey key) {
214214
*/
215215
boolean isUpToDate(CacheKey key, long lastModified) {
216216
final Boolean isUpToDate = getResourceInfo(key)
217+
.map(cachedFile -> {
218+
LOG.debug("found {} for {}", cachedFile.getCacheKey(), key);
219+
return cachedFile;
220+
})
217221
.map(cachedFile -> cachedFile.isCurrent(lastModified))
218222
.orElse(false);
219223
LOG.info("isUpToDate: {} = {}", key, isUpToDate);

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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
class CacheKey {
1111

1212
private final URL location;
13+
private final String locationString;
1314
private final VersionId version;
1415

1516
public CacheKey(final URL location, final VersionId version) {
1617
this.location = requireNonNull(location, "location");
18+
this.locationString = location.toString();
1719
this.version = version;
1820
}
1921

@@ -28,7 +30,7 @@ public VersionId getVersion() {
2830
@Override
2931
public String toString() {
3032
return "CacheKey{" +
31-
"location=" + location +
33+
"location=" + locationString +
3234
", version=" + version +
3335
'}';
3436
}
@@ -38,11 +40,15 @@ public boolean equals(final Object o) {
3840
if (this == o) return true;
3941
if (o == null || getClass() != o.getClass()) return false;
4042
CacheKey cacheKey = (CacheKey) o;
41-
return location.equals(cacheKey.location) && Objects.equals(version, cacheKey.version);
43+
return Objects.equals(locationString, cacheKey.locationString) && Objects.equals(version, cacheKey.version);
4244
}
4345

4446
@Override
4547
public int hashCode() {
46-
return Objects.hash(location, version);
48+
return Objects.hash(locationString, version);
49+
}
50+
51+
public boolean matches(URL resource) {
52+
return resource != null && locationString.equals(resource.toString());
4753
}
4854
}

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)