|
37 | 37 | import java.util.Collections; |
38 | 38 | import java.util.HashSet; |
39 | 39 | import java.util.List; |
| 40 | +import java.util.Random; |
40 | 41 | import java.util.Set; |
41 | 42 |
|
42 | 43 | import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.EnumeratingWhitelist.MethodSignature; |
@@ -98,26 +99,50 @@ static void sanity(URL definition) throws Exception { |
98 | 99 |
|
99 | 100 |
|
100 | 101 | for (EnumeratingWhitelist.Signature sig : sigs) { |
| 102 | + if (KNOWN_GOOD_SIGNATURES.contains(sig)) { |
| 103 | + continue; |
| 104 | + } |
101 | 105 | try { |
102 | 106 | assertTrue(sig + " does not exist (or is an override)", sig.exists()); |
103 | 107 | } catch (ClassNotFoundException x) { |
104 | | - if (!KNOWN_GOOD_SIGNATURES.contains(sig)) { |
105 | | - throw new Exception("Unable to verify existence of " + sig, x); |
106 | | - } |
| 108 | + // Wrapping exception to include the full signature in the error message. |
| 109 | + throw new Exception("Unable to verify existence of " + sig, x); |
107 | 110 | } |
108 | 111 | } |
109 | 112 | } |
110 | 113 |
|
111 | 114 | /** |
112 | | - * A set of signatures that are well-formed, but for which {@link Signature#exists} throws an exception because |
113 | | - * they involve types that are not available on the classpath when these tests run. |
| 115 | + * A set of signatures that are well-formed, but for which {@link Signature#exists} may throw an exception depending |
| 116 | + * on the test environment. |
114 | 117 | */ |
115 | 118 | private static final Set<Signature> KNOWN_GOOD_SIGNATURES = new HashSet<>(Arrays.asList( |
116 | | - // From blacklist |
117 | | - new MethodSignature("org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper", "getRawBuild", new String[0]), |
118 | | - // From generic-whitelist |
| 119 | + // From workflow-support, which is not a dependency of this plugin. |
| 120 | + new MethodSignature("org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper", "getRawBuild"), |
| 121 | + // From groovy-cps, which is not a dependency of this plugin. |
119 | 122 | new StaticMethodSignature("com.cloudbees.groovy.cps.CpsDefaultGroovyMethods", "each", |
120 | | - new String[] { "java.util.Iterator", "groovy.lang.Closure" }) |
| 123 | + "java.util.Iterator", "groovy.lang.Closure"), |
| 124 | + // Overrides CharSequence.isEmpty in Java 15+. |
| 125 | + new MethodSignature(String.class, "isEmpty"), |
| 126 | + // Does not exist until Java 15. |
| 127 | + new MethodSignature(CharSequence.class, "isEmpty"), |
| 128 | + // Override the corresponding RandomGenerator methods in Java 17+. |
| 129 | + new MethodSignature(Random.class, "nextBoolean"), |
| 130 | + new MethodSignature(Random.class, "nextBytes", byte[].class), |
| 131 | + new MethodSignature(Random.class, "nextDouble"), |
| 132 | + new MethodSignature(Random.class, "nextFloat"), |
| 133 | + new MethodSignature(Random.class, "nextGaussian"), |
| 134 | + new MethodSignature(Random.class, "nextInt"), |
| 135 | + new MethodSignature(Random.class, "nextInt", int.class), |
| 136 | + new MethodSignature(Random.class, "nextLong"), |
| 137 | + // Do not exist until Java 17. |
| 138 | + new MethodSignature("java.util.random.RandomGenerator", "nextBoolean"), |
| 139 | + new MethodSignature("java.util.random.RandomGenerator", "nextBytes", "byte[]"), |
| 140 | + new MethodSignature("java.util.random.RandomGenerator", "nextDouble"), |
| 141 | + new MethodSignature("java.util.random.RandomGenerator", "nextFloat"), |
| 142 | + new MethodSignature("java.util.random.RandomGenerator", "nextGaussian"), |
| 143 | + new MethodSignature("java.util.random.RandomGenerator", "nextInt"), |
| 144 | + new MethodSignature("java.util.random.RandomGenerator", "nextInt", "int"), |
| 145 | + new MethodSignature("java.util.random.RandomGenerator", "nextLong") |
121 | 146 | )); |
122 | 147 |
|
123 | 148 | @Test public void sanity() throws Exception { |
|
0 commit comments