Skip to content
Permalink
Browse files
8292739: Invalid legacy entries may be returned by Provider.getServic…
…es() call

Reviewed-by: weijun
  • Loading branch information
Valerie Peng committed Aug 24, 2022
1 parent 568be58 commit 14623c6087105a4228ff190e9e27372729b2bc4b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
@@ -1321,7 +1321,13 @@ public Set<Service> getServices() {
set.addAll(serviceMap.values());
}
if (!legacyMap.isEmpty()) {
set.addAll(legacyMap.values());
legacyMap.entrySet().forEach(entry -> {
if (!entry.getValue().isValid()) {
legacyMap.remove(entry.getKey(), entry.getValue());
} else {
set.add(entry.getValue());
}
});
}
serviceSet = Collections.unmodifiableSet(set);
servicesChanged = false;
@@ -23,7 +23,7 @@

/*
* @test
* @bug 5097015 8130181 8279222
* @bug 5097015 8130181 8279222 8292739
* @summary make sure we correctly treat Provider string entries as case insensitive
* @author Andreas Sterbenz
*/
@@ -42,15 +42,23 @@ public class CaseSensitiveServices extends Provider {
put("MESSAGEDIGEST.BAZ", "com.Baz");
// reassign the DEF alias to algorithm Bar
put("ALg.aliaS.MESSAGEdigest.DEF", "Bar");
// invalid entry since it misses the corresponding impl class info
// e.g. put("MessageDigest.Invalid", "implClass");
put("MessageDigest.Invalid xYz", "aBc");
}

public static void main(String[] args) throws Exception {
Provider p = new CaseSensitiveServices();
System.out.println(p.getServices());

System.out.println("Services: " + p.getServices());

if (p.getServices().size() != 3) {
throw new Exception("services.size() should be 3");
}

if (p.getService("MessageDigest", "Invalid") != null) {
throw new Exception("Invalid service returned");
}
Service s = testService(p, "MessageDigest", "fOO");
String val = s.getAttribute("Xyz");
if ("aBc".equals(val) == false) {
@@ -70,7 +78,8 @@ public static void main(String[] args) throws Exception {
System.out.println("OK");
}

private static Service testService(Provider p, String type, String alg) throws Exception {
private static Service testService(Provider p, String type, String alg)
throws Exception {
System.out.println("Getting " + type + "." + alg + "...");
Service s = p.getService(type, alg);
System.out.println(s);

1 comment on commit 14623c6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.