/** * Returns true iif the test case execution has thrown an instance of ExceptionInInitializerError * * @param execResult of the test case execution * @return true if the test case has thrown an ExceptionInInitializerError */ private static boolean hasThrownInitializerError(ExecutionResult execResult) { for (Throwable t : execResult.getAllThrownExceptions()) { if (t instanceof ExceptionInInitializerError) { return true; } } return false; }
/** * Returns the initialized error from the test case execution * * @param execResult of the test case execution * @return null if there were no thrown instances of ExceptionInInitializerError */ private static ExceptionInInitializerError getInitializerError(ExecutionResult execResult) { for (Throwable t : execResult.getAllThrownExceptions()) { if (t instanceof ExceptionInInitializerError) { ExceptionInInitializerError exceptionInInitializerError = (ExceptionInInitializerError)t; return exceptionInInitializerError; } } return null; }
private void initializeTargetClass() throws Throwable { String cp = ClassPathHandler.getInstance().getTargetProjectClasspath(); // Here is where the <clinit> code should be invoked for the first time DefaultTestCase test = buildLoadTargetClassTestCase(Properties.TARGET_CLASS); ExecutionResult execResult = TestCaseExecutor.getInstance().execute(test, Integer.MAX_VALUE); if (hasThrownInitializerError(execResult)) { // create single test suite with Class.forName() writeJUnitTestSuiteForFailedInitialization(); ExceptionInInitializerError ex = getInitializerError(execResult); throw ex; } else if (!execResult.getAllThrownExceptions().isEmpty()) { // some other exception has been thrown during initialization Throwable t = execResult.getAllThrownExceptions().iterator().next(); throw t; } DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator))); LoggingUtils.getEvoLogger().info("* " + ClientProcess.getPrettyPrintIdentifier() + "Finished analyzing classpath"); }