This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 539ba9b4b8 minor refactor: remove URL constructor deprecation warnings 
(cont'd)
539ba9b4b8 is described below

commit 539ba9b4b88a120afaa57073b2d41ae93e849b19
Author: Paul King <[email protected]>
AuthorDate: Sat Apr 4 06:24:29 2026 +1000

    minor refactor: remove URL constructor deprecation warnings (cont'd)
---
 src/main/java/groovy/lang/GroovyClassLoader.java | 3 ++-
 src/main/java/groovy/lang/GroovyCodeSource.java  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java 
b/src/main/java/groovy/lang/GroovyClassLoader.java
index b786ee181b..661d7e3ed5 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/groovy/lang/GroovyClassLoader.java
@@ -218,7 +218,8 @@ public class GroovyClassLoader extends URLClassLoader {
     public Class defineClass(final ClassNode classNode, final String file, 
final String newCodeBase) {
         CodeSource codeSource = null;
         try {
-            codeSource = new CodeSource(new URI("file", "", newCodeBase, 
null).toURL(), (java.security.cert.Certificate[]) null);
+            String path = newCodeBase.startsWith("/") ? newCodeBase : "/" + 
newCodeBase;
+            codeSource = new CodeSource(new URI("file", "", path, 
null).toURL(), (java.security.cert.Certificate[]) null);
         } catch (MalformedURLException | URISyntaxException ignore) {
         }
 
diff --git a/src/main/java/groovy/lang/GroovyCodeSource.java 
b/src/main/java/groovy/lang/GroovyCodeSource.java
index 8e7a20ad55..6f98dee1e6 100644
--- a/src/main/java/groovy/lang/GroovyCodeSource.java
+++ b/src/main/java/groovy/lang/GroovyCodeSource.java
@@ -232,7 +232,8 @@ public class GroovyCodeSource {
             sm.checkPermission(new GroovyCodeSourcePermission(codeBase));
         }
         try {
-            return new CodeSource(new URI("file", "", codeBase, null).toURL(), 
(java.security.cert.Certificate[]) null);
+            String path = codeBase.startsWith("/") ? codeBase : "/" + codeBase;
+            return new CodeSource(new URI("file", "", path, null).toURL(), 
(java.security.cert.Certificate[]) null);
         }
         catch (MalformedURLException | URISyntaxException e) {
             throw new RuntimeException("A CodeSource file URL cannot be 
constructed from the supplied codeBase: " + codeBase);

Reply via email to