Skip to content

Commit f690fbd

Browse files
committed
Replace Set<URL> with UrlKey or List
1 parent 71cb061 commit f690fbd

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/MissingALACAttributePanel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
import java.net.MalformedURLException;
6868
import java.net.URISyntaxException;
6969
import java.net.URL;
70-
import java.util.HashSet;
71-
import java.util.Set;
70+
import java.util.ArrayList;
71+
import java.util.List;
7272

7373
/**
7474
* http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/manifest.html#app_library
@@ -151,7 +151,7 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
151151
}
152152

153153
public static void main(String[] args) throws MalformedURLException {
154-
Set<URL> s = new HashSet<>();
154+
List<URL> s = new ArrayList<>();
155155
s.add(new URL("http:/blah.com/blah"));
156156
s.add(new URL("http:/blah.com/blah/blah"));
157157
MissingALACAttributePanel w = new MissingALACAttributePanel(null, "HelloWorld", "http://nbblah.url", UrlUtils.setOfUrlsToHtmlList(s));

core/src/main/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogs.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
import java.net.URL;
5959
import java.security.AccessController;
6060
import java.security.PrivilegedAction;
61-
import java.util.Set;
61+
import java.util.List;
6262
import java.util.concurrent.Semaphore;
6363

6464
/**
@@ -221,7 +221,7 @@ public static NamePassword showAuthenticationPrompt(String host, int port, Strin
221221
return (NamePassword) response;
222222
}
223223

224-
public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase, Set<URL> remoteUrls) {
224+
public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase, List<URL> remoteUrls) {
225225

226226
SecurityDialogMessage message = new SecurityDialogMessage(file);
227227
message.dialogType = DialogType.MISSING_ALACA;
@@ -242,7 +242,7 @@ public static boolean showMissingALACAttributePanel(JNLPFile file, URL codeBase,
242242
return selectedValue.toBoolean();
243243
}
244244

245-
public static boolean showMatchingALACAttributePanel(JNLPFile file, URL documentBase, Set<URL> remoteUrls) {
245+
public static boolean showMatchingALACAttributePanel(JNLPFile file, URL documentBase, List<URL> remoteUrls) {
246246

247247
SecurityDialogMessage message = new SecurityDialogMessage(file);
248248
message.dialogType = DialogType.MATCHING_ALACA;

core/src/main/java/net/adoptopenjdk/icedteaweb/manifest/ManifestAttributesChecker.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,20 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx
332332
final URL codebase = file.getCodeBase();
333333

334334
//cases
335-
final Map<UrlKey, Set<URL>> usedUrls = new HashMap<>();
335+
final Map<UrlKey, Set<UrlKey>> usedUrls = new HashMap<>();
336336
final URL sourceLocation = file.getSourceLocation();
337337
final ResourcesDesc[] resourcesDescs = file.getResourcesDescs();
338338
if ((sourceLocation != null) && !FILE_PROTOCOL.equals(sourceLocation.getProtocol())) {
339339
final URL urlWithoutFileName = UrlUtils.removeFileName(sourceLocation);
340-
usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(sourceLocation);
340+
usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(new UrlKey(sourceLocation));
341341
}
342342
for (ResourcesDesc resourcesDesc : resourcesDescs) {
343343
ExtensionDesc[] ex = resourcesDesc.getExtensions();
344344
if (ex != null) {
345345
for (ExtensionDesc extensionDesc : ex) {
346346
if (extensionDesc != null) {
347347
final URL urlWithoutFileName = UrlUtils.removeFileName(extensionDesc.getLocation());
348-
usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(extensionDesc.getLocation());
348+
usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(new UrlKey(extensionDesc.getLocation()));
349349
}
350350
}
351351
}
@@ -354,7 +354,7 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx
354354
for (JARDesc jarDesc : jars) {
355355
if (jarDesc != null) {
356356
final URL urlWithoutFileName = UrlUtils.removeFileName(jarDesc.getLocation());
357-
usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(jarDesc.getLocation());
357+
usedUrls.computeIfAbsent(new UrlKey(urlWithoutFileName), url -> new HashSet<>()).add(new UrlKey(jarDesc.getLocation()));
358358
}
359359
}
360360
}
@@ -366,7 +366,7 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx
366366
LOG.debug("The application is not using any url resources, skipping Application-Library-Allowable-Codebase Attribute check.");
367367
return;
368368
}
369-
final Set<URL> notOkUrls = new HashSet<>();
369+
final Set<UrlKey> notOkUrls = new HashSet<>();
370370
final boolean skipResourcesFromFileSystem = Boolean.parseBoolean(JNLPRuntime.getConfiguration().getProperty(ConfigurationConstants.KEY_ASSUME_FILE_STEM_IN_CODEBASE));
371371
for (UrlKey urlKey : usedUrls.keySet()) {
372372
final URL u = urlKey.getUrl();
@@ -375,7 +375,7 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx
375375
} else if (skipResourcesFromFileSystem && FILE_PROTOCOL.equals(u.getProtocol())) {
376376
LOG.debug("OK - '{}' is from file system", u);
377377
} else {
378-
notOkUrls.add(u);
378+
notOkUrls.add(urlKey);
379379
LOG.warn("Warning! '{}' is NOT from codebase '{}'.", u, codebase);
380380
}
381381
}
@@ -393,9 +393,11 @@ private void checkApplicationLibraryAllowableCodebaseAttribute() throws LaunchEx
393393
att = null;
394394
}
395395

396-
final Set<URL> notOkResources = notOkUrls.stream()
397-
.flatMap(notOk -> usedUrls.get(new UrlKey(notOk)).stream())
398-
.collect(Collectors.toSet());
396+
final List<URL> notOkResources = notOkUrls.stream()
397+
.flatMap(notOk -> usedUrls.get(notOk).stream())
398+
.collect(Collectors.toSet()).stream()
399+
.map(UrlKey::getUrl)
400+
.collect(Collectors.toList());
399401

400402
notOkResources.forEach(url -> LOG.warn("The resource '{}' is not from codebase '{}'", url, codebase));
401403

core/src/main/java/net/sourceforge/jnlp/util/UrlUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import java.nio.charset.Charset;
6161
import java.nio.charset.StandardCharsets;
6262
import java.util.Collection;
63+
import java.util.List;
6364
import java.util.Objects;
6465

6566
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -226,7 +227,7 @@ public static URL removeFileName(final URL src) {
226227
* @param remoteUrls list of urls
227228
* @return String containing html item list of those urls
228229
*/
229-
public static String setOfUrlsToHtmlList(final Collection<URL> remoteUrls) {
230+
public static String setOfUrlsToHtmlList(final List<URL> remoteUrls) {
230231
return setOfUrlsToHtmlList(remoteUrls, 4);
231232
}
232233

core/src/test/java/net/adoptopenjdk/icedteaweb/client/parts/dialogs/security/SecurityDialogsTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
import java.lang.reflect.Field;
6767
import java.net.MalformedURLException;
6868
import java.net.URL;
69-
import java.util.HashSet;
69+
import java.util.ArrayList;
7070

7171
@Ignore
7272
public class SecurityDialogsTest extends NoStdOutErrTest {
@@ -312,9 +312,9 @@ private void testAllDialogs(ExpectedResults r) throws MalformedURLException {
312312
//Assert.assertEquals(r.ea, r5);
313313
NamePassword r6 = SecurityDialogs.showAuthenticationPrompt(null, 123456, null, null);
314314
Assert.assertEquals(r.np, r6);
315-
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new HashSet<URL>());
315+
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>());
316316
Assert.assertEquals(r.b, r7);
317-
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
317+
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
318318
Assert.assertEquals(r.b, r8);
319319
boolean r9 = SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF());
320320
Assert.assertEquals(r.b, r9);
@@ -336,9 +336,9 @@ private void testAllDialogsNullResults() throws MalformedURLException {
336336
//Assert.assertEquals(r.ea, r5);
337337
NamePassword r6 = SecurityDialogs.showAuthenticationPrompt(null, 123456, null, null);
338338
Assert.assertEquals(null, r6);
339-
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new HashSet<URL>());
339+
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>());
340340
Assert.assertEquals(false, r7);
341-
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
341+
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
342342
Assert.assertEquals(false, r8);
343343
boolean r9 = SecurityDialogs.showMissingPermissionsAttributeDialogue(crtJnlpF());
344344
Assert.assertEquals(false, r9);
@@ -441,7 +441,7 @@ private void countNPES(int allowedRuns) throws MalformedURLException {
441441
}
442442
try {
443443
metcounter++;
444-
SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
444+
SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
445445
} catch (NullPointerException ex) {
446446
npecounter++;
447447
}
@@ -628,9 +628,9 @@ public void testUnsignedDialogsNotHeadlessPrompt() throws Exception {
628628
+ ".* \\Q" + urlstr + "\\E ";
629629

630630
private void runRememeberableClasses(ExpectedResults r) throws MalformedURLException {
631-
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new HashSet<URL>());
631+
boolean r7 = SecurityDialogs.showMissingALACAttributePanel(crtJnlpF(), null, new ArrayList<>());
632632
Assert.assertEquals(r.b, r7);
633-
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new HashSet<URL>());
633+
boolean r8 = SecurityDialogs.showMatchingALACAttributePanel(crtJnlpF(), url, new ArrayList<>());
634634
Assert.assertEquals(r.b, r8);
635635
boolean r9 = testUnsignedBehaviour();
636636
Assert.assertEquals(r.b, r9);

0 commit comments

Comments
 (0)