changeset 312:187018b03218

Runners: fail gracefully when generated runner class cannot be loaded by the older JDK.
author shade
date Fri, 22 Jul 2016 18:41:47 +0300
parents 92056492425b
children dffc5e0cabcf
files jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java jcstress-core/src/main/java/org/openjdk/jcstress/util/Reflections.java
diffstat 2 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Thu Jul 21 23:04:16 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Fri Jul 22 18:41:47 2016 +0300
@@ -38,10 +38,7 @@
 import org.openjdk.jcstress.util.InputStreamDrainer;
 import org.openjdk.jcstress.vm.VMSupport;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.PrintWriter;
+import java.io.*;
 import java.lang.management.ManagementFactory;
 import java.lang.reflect.Constructor;
 import java.util.*;
@@ -240,8 +237,14 @@
             Constructor<?> cnstr = aClass.getConstructor(TestConfig.class, TestResultCollector.class, ExecutorService.class);
             Runner<?> o = (Runner<?>) cnstr.newInstance(config, collector, pool);
             o.run();
+        } catch (ClassFormatError e) {
+            TestResult result = new TestResult(config, Status.API_MISMATCH, 0);
+            result.addAuxData(e.getMessage());
+            collector.add(result);
         } catch (Exception ex) {
-            throw new IllegalStateException("Should have been handled within the Runner");
+            TestResult result = new TestResult(config, Status.TEST_ERROR, 0);
+            result.addAuxData(ex.getMessage());
+            collector.add(result);
         }
     }
 
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/util/Reflections.java	Thu Jul 21 23:04:16 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/util/Reflections.java	Fri Jul 22 18:41:47 2016 +0300
@@ -72,6 +72,8 @@
                 throw new IllegalStateException(e.getMessage(), e);
             } catch (NoClassDefFoundError e) {
                 // may happen in JDK 9+ while trying to load a privileged class
+            } catch (NoSuchMethodError | NoSuchFieldError | ClassFormatError e) {
+                // may happen when trying to load a class from a newer JDK
             }
         }
         return newClasses;