Skip to content

Commit

Permalink
8279222: Incorrect legacyMap.get in java.security.Provider after JDK-…
Browse files Browse the repository at this point in the history
…8276660

Co-authored-by: Valerie Peng <valeriep@openjdk.org>
Reviewed-by: alanb, valeriep
  • Loading branch information
shipilev and Valerie Peng committed Jan 5, 2022
1 parent f8f9148 commit 0f4807e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/security/Provider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1149,7 +1149,7 @@ private void parseLegacy(String name, String value, OPType opType) {
switch (opType) {
case ADD:
// clean up old alias if present
Service prevAliasService = legacyMap.get(aliasAlg);
Service prevAliasService = legacyMap.get(aliasKey);
if (prevAliasService != null) {
prevAliasService.removeAlias(aliasAlg);
}
Expand Down
20 changes: 16 additions & 4 deletions test/jdk/java/security/Provider/CaseSensitiveServices.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

/*
* @test
* @bug 5097015 8130181
* @bug 5097015 8130181 8279222
* @summary make sure we correctly treat Provider string entries as case insensitive
* @author Andreas Sterbenz
*/
Expand All @@ -36,9 +36,12 @@ public class CaseSensitiveServices extends Provider {
super("Foo", "1.0", null);
put("MessageDigest.Foo", "com.Foo");
put("mESSAGEdIGEST.fOO xYz", "aBc");
put("ALg.aliaS.MESSAGEdigest.Fu", "FoO");
// first assign the DEF alias to algorithm Foo
put("ALg.aliaS.MESSAGEdigest.DEF", "FoO");
put("messageDigest.Bar", "com.Bar");
put("MESSAGEDIGEST.BAZ", "com.Baz");
// reassign the DEF alias to algorithm Bar
put("ALg.aliaS.MESSAGEdigest.DEF", "Bar");
}

public static void main(String[] args) throws Exception {
Expand All @@ -47,12 +50,21 @@ public static void main(String[] args) throws Exception {
if (p.getServices().size() != 3) {
throw new Exception("services.size() should be 3");
}

Service s = testService(p, "MessageDigest", "fOO");
String val = s.getAttribute("Xyz");
if ("aBc".equals(val) == false) {
throw new Exception("Wrong value: " + val);
}
testService(p, "MessageDigest", "fU");
if (s.toString().indexOf("DEF") != -1) {
throw new Exception("Old alias DEF should be removed");
}

// test Service alias DEF and its associated impl is Bar
s = testService(p, "MessageDigest", "DeF");
if (s.getAttribute("Xyz") != null) {
throw new Exception("DEF mapped to the wrong impl");
}
testService(p, "MessageDigest", "BAR");
testService(p, "MessageDigest", "baz");
System.out.println("OK");
Expand Down

0 comments on commit 0f4807e

Please sign in to comment.