Updated Branches: refs/heads/master 99b3115cc -> 15ad61f56
[SUREFIRE-979] Wrong classloader used when test fails in static initializer of base class Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/15ad61f5 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/15ad61f5 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/15ad61f5 Branch: refs/heads/master Commit: 15ad61f56ebe215e84db892256361a51cac68d7d Parents: 99b3115 Author: Kristian Rosenvold <[email protected]> Authored: Tue Mar 26 12:26:21 2013 +0100 Committer: Kristian Rosenvold <[email protected]> Committed: Tue Mar 26 16:55:47 2013 +0100 ---------------------------------------------------------------------- .../maven/surefire/booter/ProviderFactory.java | 4 +- .../its/jiras/Surefire979WrongClassLoaderIT.java | 39 +++++++++++++++ .../module1/pom.xml | 36 +++++++++++++ .../src/main/java/surefire979/TestBase.java | 17 ++++++ .../module2/pom.xml | 37 ++++++++++++++ .../surefire979/FailingStaticInitializerTest.java | 17 ++++++ .../pom.xml | 28 ++++++++++ .../surefire/report/SmartStackTraceParser.java | 2 +- 8 files changed, 177 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java index abef1c6..a21da57 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java @@ -97,7 +97,7 @@ public class ProviderFactory public SurefireProvider createProvider( boolean isInsideFork ) { - ClassLoader context = java.lang.Thread.currentThread().getContextClassLoader(); + ClassLoader systemClassLoader = java.lang.Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader( surefireClassLoader ); StartupConfiguration starterConfiguration = startupConfiguration; @@ -113,7 +113,7 @@ public class ProviderFactory surefireReflector.setIfDirScannerAware( o, providerConfiguration.getDirScannerParams() ); Object provider = surefireReflector.instantiateProvider( starterConfiguration.getProviderClassName(), o ); - Thread.currentThread().setContextClassLoader( context ); + Thread.currentThread().setContextClassLoader( systemClassLoader ); return new ProviderProxy( provider, testsClassLoader ); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire979WrongClassLoaderIT.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire979WrongClassLoaderIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire979WrongClassLoaderIT.java new file mode 100644 index 0000000..d648576 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire979WrongClassLoaderIT.java @@ -0,0 +1,39 @@ +package org.apache.maven.surefire.its.jiras; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.surefire.its.fixture.OutputValidator; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.junit.Test; + +public class Surefire979WrongClassLoaderIT + extends SurefireJUnit4IntegrationTestCase +{ + + @Test + public void wrongClassloaderUSedInSmartStacktraceparser() + throws Exception + { + OutputValidator outputValidator = + unpack( "surefire-979-smartStackTrace-wrongClassloader" ).failNever().executeTest(); + outputValidator.verifyTextInLog( "java.lang.NoClassDefFoundError: org/apache/commons/io/input/AutoCloseInputStream" ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/pom.xml b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/pom.xml new file mode 100644 index 0000000..ccd8a05 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/pom.xml @@ -0,0 +1,36 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>surefire-979</groupId> + <artifactId>module1</artifactId> + <version>1.0</version> + <name>surefire-979-base</name> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.10</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.2</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.5.1</version> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.version}</version> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/src/main/java/surefire979/TestBase.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/src/main/java/surefire979/TestBase.java b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/src/main/java/surefire979/TestBase.java new file mode 100644 index 0000000..4cba852 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module1/src/main/java/surefire979/TestBase.java @@ -0,0 +1,17 @@ +package surefire979; + + +import org.apache.commons.io.input.AutoCloseInputStream; +import org.junit.Test; + +import java.io.ByteArrayInputStream; + + +public class TestBase +{ + + static { + AutoCloseInputStream directoryWalker = new AutoCloseInputStream(new ByteArrayInputStream(new byte[200])); + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/pom.xml b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/pom.xml new file mode 100644 index 0000000..a0c12a9 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/pom.xml @@ -0,0 +1,37 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>surefire-979</groupId> + <artifactId>module2</artifactId> + <version>1.0</version> + <name>surefire-979</name> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.10</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>surefire-979</groupId> + <artifactId>module1</artifactId> + <version>1.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.5.1</version> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.version}</version> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/src/test/java/surefire979/FailingStaticInitializerTest.java ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/src/test/java/surefire979/FailingStaticInitializerTest.java b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/src/test/java/surefire979/FailingStaticInitializerTest.java new file mode 100644 index 0000000..dd37362 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/module2/src/test/java/surefire979/FailingStaticInitializerTest.java @@ -0,0 +1,17 @@ +package surefire979; + + +import org.junit.Test; + + +public class FailingStaticInitializerTest extends TestBase +{ + + @Test + public void test() + { + throw new IllegalStateException("This test will never run"); + + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/pom.xml ---------------------------------------------------------------------- diff --git a/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/pom.xml b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/pom.xml new file mode 100644 index 0000000..d540d1b --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-979-smartStackTrace-wrongClassloader/pom.xml @@ -0,0 +1,28 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>surefire-979</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>surefire-979</name> + <packaging>pom</packaging> + + <modules> + <module>module1</module> + <module>module2</module> + </modules> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.5.1</version> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.version}</version> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/15ad61f5/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java ---------------------------------------------------------------------- diff --git a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java index 13bc6c9..ec67df8 100644 --- a/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java +++ b/surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java @@ -59,7 +59,7 @@ public class SmartStackTraceParser { try { - return Class.forName( name ); + return Thread.currentThread().getContextClassLoader().loadClass( name ); } catch ( ClassNotFoundException e ) {
