8175874: Update Security.insertProviderAt to specify behavior when requested position is out of range.
Reviewed-by: mullan, valeriep
This commit is contained in:
parent
dbb788f34d
commit
9435cd1916
src/java.base/share/classes/java/security
test/jdk/java/security/Provider
@ -296,7 +296,10 @@ public final class Security {
|
||||
* Adds a new provider, at a specified position. The position is
|
||||
* the preference order in which providers are searched for
|
||||
* requested algorithms. The position is 1-based, that is,
|
||||
* 1 is most preferred, followed by 2, and so on.
|
||||
* 1 is most preferred, followed by 2, and so on. If the position
|
||||
* is less than 1 or greater than n, where n is the number of installed
|
||||
* providers, the provider (if not already installed) is inserted at
|
||||
* the end of the list, or at the n + 1 position.
|
||||
*
|
||||
* <p>If the given provider is installed at the requested position,
|
||||
* the provider that used to be at that position, and all providers
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4856968 7054918 8130181
|
||||
* @bug 4856968 7054918 8130181 8175874
|
||||
* @library ../testlibrary
|
||||
* @summary make sure add/insert/removeProvider() work correctly
|
||||
* @author Andreas Sterbenz
|
||||
@ -81,6 +81,19 @@ public class ChangeProviders extends Provider {
|
||||
throw new Exception("Provider not at pos 1");
|
||||
}
|
||||
|
||||
// Ensure that providers inserted at positions outside of [1..n] are placed
|
||||
// at the n+1st position
|
||||
Security.removeProvider(p.getName());
|
||||
Security.insertProviderAt(p, 0);
|
||||
if (plen() != n + 1 || Security.getProviders()[n] != p) {
|
||||
throw new Exception("Provider inserted at zero not at pos n+1");
|
||||
}
|
||||
Security.removeProvider(p.getName());
|
||||
Security.insertProviderAt(p, n + 5);
|
||||
if (plen() != n + 1 || Security.getProviders()[n] != p) {
|
||||
throw new Exception("Provider inserted at n+5 not at pos n+1");
|
||||
}
|
||||
|
||||
System.out.println("All tests passed.");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user