Make stx:libjava tests to compile using JDK 11
authorJan Vrany <jan.vrany@labware.com>
Tue, 09 Aug 2022 14:32:49 +0100
changeset 4011 1e5cf64a3779
parent 4010 19843598d34b
child 4012 117835eb9839
Make stx:libjava tests to compile using JDK 11 This commit fixes some test to compile using JDK 11 and those that cannot be fixed it removes (with regrets). The reason is that it is becoming increasingly difficult to maintain systems with JDK 7 for Smalltalk/X and JDK 11 for the rest. Most importantly, Jenkins now requires JDK 11 (which is reasonable requirement). On top of that, stx:libjava is not being developed in years, it is lagging behind Java development and as such, it is kept just a reminiscent of past that is becoming a drag. And this commit is just makeing it a bit less of a drag.
tests/java/classloader-tests-classes/src/ClassWithNestedAnnotations.java
tests/java/src/stx/libjava/tests/lang/AnnotationTests.java
tests/java/src/stx/libjava/tests/lang/ThreadStopTests.java
tests/java/src/stx/libjava/tests/lib/java/util/jar/JarFileTests.java
tests/java/src/stx/libjava/tests/vm/XAND_and_XOR.java
--- a/tests/java/classloader-tests-classes/src/ClassWithNestedAnnotations.java	Mon Nov 29 16:36:55 2021 +0000
+++ b/tests/java/classloader-tests-classes/src/ClassWithNestedAnnotations.java	Tue Aug 09 14:32:49 2022 +0100
@@ -1,11 +1,6 @@
 import java.util.List;
 
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElements;
-
-
 @stx.libjava.annotation.Package("stx:libjava/tests")
 public class ClassWithNestedAnnotations {
-	@XmlElements(@XmlElement(name = "Text", namespace = "http://www.w3.org/2003/05/soap-envelope"))
     private final List<Integer> field = null;
 }
--- a/tests/java/src/stx/libjava/tests/lang/AnnotationTests.java	Mon Nov 29 16:36:55 2021 +0000
+++ b/tests/java/src/stx/libjava/tests/lang/AnnotationTests.java	Tue Aug 09 14:32:49 2022 +0100
@@ -11,9 +11,6 @@
 import java.net.URLClassLoader;
 import java.util.List;
 
-import javax.xml.bind.annotation.XmlElement; // get some nice annotations
-import javax.xml.bind.annotation.XmlElements;// get some nice annotations
-
 import static org.junit.Assert.assertTrue;
 
 @stx.libjava.annotation.Package("stx:libjava/tests")
--- a/tests/java/src/stx/libjava/tests/lang/ThreadStopTests.java	Mon Nov 29 16:36:55 2021 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-package stx.libjava.tests.lang;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-@stx.libjava.annotation.Package("stx:libjava/tests")
-public class ThreadStopTests {
-    
-    protected void giveUp() {
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException ie) {
-            // Lovely, really. Very Javaish.  
-        }
-    }
-    
-    @Test
-    public void test_kill_02() {
-        Worker worker = new Worker();
-        Thread workerT = new Thread(worker);
-        
-        workerT.start();
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException ie) {
-            // Do nothing. I love this Java idiom! 
-        }
-        workerT.interrupt();
-        workerT.stop();
-        giveUp();
-                
-        assertTrue(worker.started);
-        assertTrue(worker.killed);
-        assertFalse(worker.aborted);
-        assertFalse(worker.finished);
-    }
-
-    @Test
-    public void test_kill_01() {
-        Worker worker = new Worker();
-        Thread workerT = new Thread(worker);
-        
-        workerT.start();
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException ie) {
-            // Do nothing. I love this Java idiom! 
-        }
-        workerT.stop();
-        giveUp();
-                
-        assertTrue(worker.started);
-        assertTrue(worker.killed);
-        assertFalse(worker.aborted);
-        assertFalse(worker.finished);
-    }
-    
-    @Test
-    public void test_abort_02() {
-        Worker worker = new Worker();
-        Thread workerT = new Thread(worker);
-        
-        workerT.start();
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException ie) {
-            // Do nothing. I love this Java idiom! 
-        }
-        workerT.interrupt();
-        workerT.stop(new AbortSignal());
-        giveUp();
-                
-        assertTrue(worker.started);
-        assertFalse(worker.killed);
-        assertTrue(worker.aborted);
-        assertFalse(worker.finished);
-    }
-
-    @Test
-    public void test_abort_01() {
-        Worker worker = new Worker();
-        Thread workerT = new Thread(worker);
-        
-        workerT.start();
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException ie) {
-            // Do nothing. I love this Java idiom! 
-        }
-        workerT.stop(new AbortSignal());
-        giveUp();
-                
-        assertTrue(worker.started);
-        assertFalse(worker.killed);
-        assertTrue(worker.aborted);
-        assertFalse(worker.finished);
-    }
-    
-    
-    class AbortSignal extends Error {
-    }
-    
-    class Worker implements Runnable {
-        public boolean started = false;
-        public boolean killed = false;
-        public boolean aborted = false;
-        public boolean finished = false;
-
-        @Override
-        public void run() {
-            started = true;
-            try {
-                work();
-                finished = true;
-                return;
-            } catch (AbortSignal ae) {
-                aborted = true;
-                return;
-            } catch (ThreadDeath td) {
-                killed = true;
-                throw td;
-            }           
-        }
-        
-        public void work() {
-            // Just to keep thread busy for some time
-            for (int i = 1; i < 3; i++) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException ie) {
-                    // Simulate a bad guy
-                    i--;
-                } catch (Exception e) {
-                    // Simulate a really bad guy
-                    i--;
-                }
-            }
-        }
-    }
-
-}
--- a/tests/java/src/stx/libjava/tests/lib/java/util/jar/JarFileTests.java	Mon Nov 29 16:36:55 2021 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-package stx.libjava.tests.lib.java.util.jar;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.CryptoPrimitive;
-import java.security.cert.Certificate;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.Enumeration;
-import java.util.Set;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import org.junit.Test;
-
-import sun.security.util.DisabledAlgorithmConstraints;
-
-/**
- * Regression tests for JarFile 
- * 
- * @author Jan Vrany <jan.vrany [at] fit.cvut.cz>
- *
- */
-@stx.libjava.annotation.Package("stx:libjava/tests")
-public class JarFileTests {
-    
-    /**
-     * This test tests signed JAR files. As of 2013-09-06, it works
-     * in interpreted mode but fails when JIT is on. 
-     */     
-    @Test    
-    public void signed_jar_01() {
-    	/* 
-    	 * Test file is signed using MD5withRSA algorithm that has been disabled
-    	 * in some versions of OpenJDK (and possibly elsewhere too - namely 
-    	 * OpenJDK 7 update 111, Debian 2.7.2 has it disabled. In that case this 
-    	 * test fail. 
-    	 * 
-    	 * So first check if MD5withRSA enabled and if not, skip the test. See
-    	 * sun.security.pkcs.SignerInfo, line ~ 389. However, we need to be careful
-    	 * here - some old JDKs have no CryptoPrimitive class and so on (older JDK 6)
-    	 * So, catch ClassNotFoundException and eventually proceed, assuming old JDKs
-    	 * have "MD5withRSA" enabled. Sigh, so hacky.
-    	 */
-    	try {
-    		Set<CryptoPrimitive> sigset = Collections.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE));
-    		DisabledAlgorithmConstraints constraints = new DisabledAlgorithmConstraints("jdk.jar.disabledAlgorithms");
-    		org.junit.Assume.assumeTrue(constraints.permits(sigset, "MD5withRSA", null));    	
-    	} catch (Exception e) {
-    		if (!(e instanceof ClassNotFoundException)) {
-    			/* 
-    			 * Some class has not been found when executing the code above.
-    			 * This could mean we're running on an oldish JDK, in that case
-    			 * proceed. Otherwise, re-throw. 
-    			 */
-    			throw e;
-    		}
-    	}
-
-        String jarfile = System.getProperty("libjava.tests.dir", "..") + "/mauve/java/src/gnu/testlet/java/util/jar/JarFile/jfaceSmall.jar";        
-        try {
-        	JarFile jar = new JarFile(jarfile);
-        	try {
-	            for (Enumeration<JarEntry> entries = jar.entries(); entries.hasMoreElements();) {
-	                JarEntry entry = entries.nextElement();
-	                if (entry.isDirectory()) {
-	                    continue;
-	                }
-	                InputStream stream = null;
-	                try {
-	                    stream = jar.getInputStream(entry);
-	                    byte[] ba = new byte[8192];
-	                    int n;
-	                    while ((n = stream.read(ba)) >= 0)
-	                  /* keep reading */;
-	                } finally {
-	                    if (stream != null) {
-	                        try {
-	                            stream.close();
-	                        } catch (IOException ignored) {
-	                        }
-	                    }
-	                }
-	                Certificate[] certs = entry.getCertificates();
-	                if (certs == null || certs.length == 0) // No certificate
-	                {
-	                    if (!entry.getName().startsWith("META-INF")) {
-	                        assertTrue("Entry " + entry.getName() + " in jar file "
-	                              + jarfile + " does not have a certificate", false);                        
-	                    }
-	                }
-	            }
-        	} finally {
-        		jar.close();
-        	}                       
-        } catch (IOException e) {            
-            e.printStackTrace();
-            assertTrue(e.getMessage(), false);
-        }
-
-    }
-
-}
--- a/tests/java/src/stx/libjava/tests/vm/XAND_and_XOR.java	Mon Nov 29 16:36:55 2021 +0000
+++ b/tests/java/src/stx/libjava/tests/vm/XAND_and_XOR.java	Tue Aug 09 14:32:49 2022 +0100
@@ -4,95 +4,112 @@
 
 import org.junit.Test;
 
-import sun.misc.DoubleConsts;
-
 
 /*
- * Test for (B/I/L)AND and (B/I/L)LOR 
+ * Test for (B/I/L)AND and (B/I/L)LOR
  */
 
 @stx.libjava.annotation.Package("stx:libjava/tests")
 public class XAND_and_XOR {
 
+    public class DoubleConsts {
+        /**
+         * Bit mask to isolate the sign bit of a <code>double</code>.
+         */
+        public static final long    SIGN_BIT_MASK   = 0x8000000000000000L;
+
+        /**
+         * Bit mask to isolate the exponent field of a
+         * <code>double</code>.
+         */
+        public static final long    EXP_BIT_MASK    = 0x7FF0000000000000L;
+
+        /**
+         * Bit mask to isolate the significand field of a
+         * <code>double</code>.
+         */
+        public static final long    SIGNIF_BIT_MASK = 0x000FFFFFFFFFFFFFL;
+    }
+
     @Test
     public void test_LAND_01() {
         long l;
-        
+
         l =-9223372036854775808L & 0L;
         assertTrue(l == 0L);
 
-               
+
         l =-9223372036854775808L & DoubleConsts.SIGN_BIT_MASK;
-        assertTrue(l != 0L);             
+        assertTrue(l != 0L);
     }
-    
+
     @Test
     public void test_LOR_01() {
         long l;
-                       
+
         l =-9223372036854775808L | 1L;
         assertTrue(l == -9223372036854775807L);
     }
-    
+
     @Test
     public void test_rawCopySign_01() {
         long magnitude = Double.doubleToRawLongBits(-0.0d);
-        long sign =      Double.doubleToRawLongBits(-1.0d);        
+        long sign =      Double.doubleToRawLongBits(-1.0d);
         long l1, l2, l3, l4;
-        
-        l1 = sign & DoubleConsts.SIGN_BIT_MASK; 
-        
+
+        l1 = sign & DoubleConsts.SIGN_BIT_MASK;
+
         l2 = DoubleConsts.EXP_BIT_MASK | DoubleConsts.SIGNIF_BIT_MASK;
-        
+
         l3 = magnitude & l2;
-        
+
         l4 = l1 | l3;
-        
+
         assertTrue(l1 == -9223372036854775808L);
         assertTrue(l2 == 9223372036854775807L);
         assertTrue(l3 == 0L);
-        assertTrue(l4 == -9223372036854775808L);               
+        assertTrue(l4 == -9223372036854775808L);
     }
 
     @Test
     public void test_rawCopySign_02() {
         long magnitude = Double.doubleToRawLongBits(-1.0d);
-        long sign =      Double.doubleToRawLongBits(-0.0d);        
+        long sign =      Double.doubleToRawLongBits(-0.0d);
         long l1, l2, l3, l4;
-        
-        l1 = sign & DoubleConsts.SIGN_BIT_MASK; 
-        
+
+        l1 = sign & DoubleConsts.SIGN_BIT_MASK;
+
         l2 = DoubleConsts.EXP_BIT_MASK | DoubleConsts.SIGNIF_BIT_MASK;
-        
+
         l3 = magnitude & l2;
-        
+
         l4 = l1 | l3;
-        
+
         assertTrue(l1 == -9223372036854775808L);
         assertTrue(l2 == 9223372036854775807L);
         assertTrue(l3 == 4607182418800017408L);
-        assertTrue(l4 == -4616189618054758400L);               
+        assertTrue(l4 == -4616189618054758400L);
     }
-    
+
     @Test
     public void test_rawCopySign_03() {
         long magnitude = Double.doubleToRawLongBits( 1.0d);
-        long sign =      Double.doubleToRawLongBits(-0.0d);        
+        long sign =      Double.doubleToRawLongBits(-0.0d);
         long l1, l2, l3, l4;
-        
-        l1 = sign & DoubleConsts.SIGN_BIT_MASK; 
-        
+
+        l1 = sign & DoubleConsts.SIGN_BIT_MASK;
+
         l2 = DoubleConsts.EXP_BIT_MASK | DoubleConsts.SIGNIF_BIT_MASK;
-        
+
         l3 = magnitude & l2;
-        
+
         l4 = l1 | l3;
-        
+
         assertTrue(l1 == -9223372036854775808L);
         assertTrue(l2 == 9223372036854775807L);
         assertTrue(l3 == 4607182418800017408L);
-        assertTrue(l4 == -4616189618054758400L);               
+        assertTrue(l4 == -4616189618054758400L);
     }
-    
+
 
 }