Description: with openjdk-21, one gets build-time errors like the one in the
 bug thread linked below. The proposed changes are not the only solutions and
 maybe not the best ones, especially if one wants to inherit some of the
 altered classes.
Author: Pierre Gruet <pgt@debian.org>
Bug-Debian: https://bugs.debian.org/1057505
Forwarded: https://gitlab.com/jexler/grengine/-/issues/7
Last-Update: 2023-12-17

--- a/src/main/java/ch/grengine/Grengine.java
+++ b/src/main/java/ch/grengine/Grengine.java
@@ -623,7 +623,7 @@
      * 
      * @since 1.0
      */
-    protected void updateEngineIfSourcesLayersModified() {
+    protected final void updateEngineIfSourcesLayersModified() {
         
         // check if lastChecked is 0 to make sure layers are set once if latency is infinite
         // check both boundaries of the interval to exclude problems with leap seconds etc.
--- a/src/main/java/ch/grengine/except/ClassNameConflictException.java
+++ b/src/main/java/ch/grengine/except/ClassNameConflictException.java
@@ -19,6 +19,7 @@
 import ch.grengine.code.Code;
 
 import java.util.List;
+import java.util.HashMap;
 import java.util.Map;
 
 
@@ -35,8 +36,8 @@
 
     private static final long serialVersionUID = -7064452473268097551L;
     
-    private final Map<String,List<Code>> sameClassNamesInMultipleCodeLayersMap;
-    private final Map<String,List<Code>> sameClassNamesInParentAndCodeLayersMap;
+    private final HashMap<String,List<Code>> sameClassNamesInMultipleCodeLayersMap;
+    private final HashMap<String,List<Code>> sameClassNamesInParentAndCodeLayersMap;
 
     /**
      * constructor from exception message and maps with class conflict information.
@@ -56,8 +57,8 @@
                 toMessageString(sameClassNamesInMultipleCodeLayersMap) +
                 ", classes in code layers and parent: " +
                 toMessageString(sameClassNamesInParentAndCodeLayersMap));
-        this.sameClassNamesInMultipleCodeLayersMap = sameClassNamesInMultipleCodeLayersMap;
-        this.sameClassNamesInParentAndCodeLayersMap = sameClassNamesInParentAndCodeLayersMap;
+        this.sameClassNamesInMultipleCodeLayersMap = (sameClassNamesInMultipleCodeLayersMap == null) ? null : new HashMap<String, List<Code>>(sameClassNamesInMultipleCodeLayersMap);
+        this.sameClassNamesInParentAndCodeLayersMap = (sameClassNamesInParentAndCodeLayersMap == null) ? null : new HashMap<String, List<Code>>(sameClassNamesInParentAndCodeLayersMap);
     }
     
     /**
--- a/src/main/java/ch/grengine/except/CompileException.java
+++ b/src/main/java/ch/grengine/except/CompileException.java
@@ -31,7 +31,7 @@
 
     private static final long serialVersionUID = -7064452473268097551L;
     
-    private final Sources sources;
+    private final transient Sources sources;
 
     /**
      * constructor from exception message and sources for which compilation failed.
--- a/src/main/java/ch/grengine/engine/Loader.java
+++ b/src/main/java/ch/grengine/engine/Loader.java
@@ -109,7 +109,7 @@
      * 
      * @since 1.0
      */
-    public void setSourceClassLoader(final EngineId engineId, final SourceClassLoader sourceClassLoader) {
+    public final void setSourceClassLoader(final EngineId engineId, final SourceClassLoader sourceClassLoader) {
         if (engineId != this.engineId) {
             throw new IllegalArgumentException("Engine ID does not match (loader created by a different engine).");
         }
--- a/src/main/java/ch/grengine/sources/CompositeSources.java
+++ b/src/main/java/ch/grengine/sources/CompositeSources.java
@@ -41,7 +41,7 @@
  * @author Alain Stalder
  * @author Made in Switzerland.
  */
-public class CompositeSources extends BaseSources {
+public final class CompositeSources extends BaseSources {
     
     private final Builder builder;
     
--- a/src/main/java/ch/grengine/sources/DirBasedSources.java
+++ b/src/main/java/ch/grengine/sources/DirBasedSources.java
@@ -47,7 +47,7 @@
  * @author Alain Stalder
  * @author Made in Switzerland.
  */
-public class DirBasedSources extends BaseSources {
+public final class DirBasedSources extends BaseSources {
         
     private final Builder builder;
 
--- a/src/main/java/ch/grengine/sources/FixedSetSources.java
+++ b/src/main/java/ch/grengine/sources/FixedSetSources.java
@@ -34,7 +34,7 @@
  * @author Alain Stalder
  * @author Made in Switzerland.
  */
-public class FixedSetSources extends BaseSources {
+public final class FixedSetSources extends BaseSources {
 
     private final Builder builder;
 
--- a/src/test/java/ch/grengine/source/MockFile.java
+++ b/src/test/java/ch/grengine/source/MockFile.java
@@ -27,7 +27,7 @@
 
 // so far, mocks only last modified
 @SuppressWarnings("serial")
-public class MockFile extends File {
+public final class MockFile extends File {
 
     private final File lastModifiedFile;
     
--- a/src/test/java/ch/grengine/source/SourceUtilTest.java
+++ b/src/test/java/ch/grengine/source/SourceUtilTest.java
@@ -20,6 +20,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -255,8 +256,8 @@
 
         // given
 
-        final URL url1 = new URL("http://foo.bar/Script1.groovy");
-        final URL url2 = new URL("http://foo.bar/Script2.groovy");
+        final URL url1 = new URI("http://foo.bar/Script1.groovy").toURL();
+        final URL url2 = new URI("http://foo.bar/Script2.groovy").toURL();
         final List<URL> urls = Arrays.asList(url1, url2);
 
         // when
@@ -275,8 +276,8 @@
 
         // given
 
-        final URL url1 = new URL("http://foo.bar/Script1.groovy");
-        final URL url2 = new URL("http://foo.bar/Script2.groovy");
+        final URL url1 = new URI("http://foo.bar/Script1.groovy").toURL();
+        final URL url2 = new URI("http://foo.bar/Script2.groovy").toURL();
 
         // when
 
@@ -294,8 +295,8 @@
 
         // given
 
-        final URL url1 = new URL("http://foo.bar/Script1.groovy");
-        final URL url2 = new URL("http://foo.bar/Script2.groovy");
+        final URL url1 = new URI("http://foo.bar/Script1.groovy").toURL();
+        final URL url2 = new URI("http://foo.bar/Script2.groovy").toURL();
         final List<URL> urls = Arrays.asList(url1, url2);
 
         // when
@@ -314,8 +315,8 @@
 
         // given
 
-        final URL url1 = new URL("http://foo.bar/Script1.groovy");
-        final URL url2 = new URL("http://foo.bar/Script2.groovy");
+        final URL url1 = new URI("http://foo.bar/Script1.groovy").toURL();
+        final URL url2 = new URI("http://foo.bar/Script2.groovy").toURL();
 
         // when
 
--- a/src/test/java/ch/grengine/manual/UserManualJavaTest.java
+++ b/src/test/java/ch/grengine/manual/UserManualJavaTest.java
@@ -4,6 +4,7 @@
 import java.io.FileNotFoundException;
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
+import java.net.URI;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -34,7 +35,7 @@
         Grengine gren = new Grengine();
         gren.run("println 'Hello World!'");
         gren.run(new File("MyScript.groovy"));
-        gren.run(new URL("http://somewhere.org/MyScript.groovy"));
+        gren.run(new URI("http://somewhere.org/MyScript.groovy").toURL());
         //--------------------------------------------
     }
     
@@ -80,7 +81,7 @@
         
         
         //--------------------------------------------
-        Script script = (Script)clazz.newInstance();
+        Script script = (Script)clazz.getDeclaredConstructor().newInstance();
         script.setBinding(binding);
         Object obj = script.run();
         //--------------------------------------------
@@ -97,8 +98,8 @@
         shell.evaluate(scriptText);
         shell.evaluate(scriptText);
         GroovyClassLoader gcl = new GroovyClassLoader();
-        ((Script)gcl.parseClass(scriptText).newInstance()).run();
-        ((Script)gcl.parseClass(scriptText).newInstance()).run();
+        ((Script)((Class<?>)gcl.parseClass(scriptText)).getDeclaredConstructor().newInstance()).run();
+        ((Script)((Class<?>)gcl.parseClass(scriptText)).getDeclaredConstructor().newInstance()).run();
         Grengine gren = new Grengine();
         gren.run(scriptText);
         gren.run(scriptText);
