From 4a821aeda72d7f81a7227d9dd76956c1bf829fc9 Mon Sep 17 00:00:00 2001 From: Steven Aerts Date: Mon, 5 Sep 2022 10:57:33 +0200 Subject: [PATCH] Adapt to String#stripIndent of java 15 `stripIndent` eclipses the `DefaultGroovyMethods` which is already in the generic-whitelist. Scripts already using this method were breaking when the JVM was upstepped as it would choose standard implementation over the one provided by groovy. --- .../scriptsecurity/sandbox/whitelists/generic-whitelist | 1 + .../scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist index a13119ef6..7c68a2e74 100644 --- a/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist +++ b/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist @@ -267,6 +267,7 @@ method java.lang.String split java.lang.String method java.lang.String split java.lang.String int method java.lang.String startsWith java.lang.String method java.lang.String startsWith java.lang.String int +method java.lang.String stripIndent method java.lang.String substring int method java.lang.String substring int int method java.lang.String toCharArray diff --git a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java index 470eabf9e..c0979241e 100644 --- a/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java +++ b/src/test/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/StaticWhitelistTest.java @@ -120,8 +120,9 @@ static void sanity(URL definition) throws Exception { "java.util.Iterator", "groovy.lang.Closure"), // Overrides CharSequence.isEmpty in Java 15+. new MethodSignature(String.class, "isEmpty"), - // Does not exist until Java 15. + // Do not exist until Java 15. new MethodSignature(CharSequence.class, "isEmpty"), + new MethodSignature(String.class, "stripIndent"), // Override the corresponding RandomGenerator methods in Java 17+. new MethodSignature(Random.class, "nextBoolean"), new MethodSignature(Random.class, "nextBytes", byte[].class),