Browse Source

Regression test for #125: Bugs198Tests.testGitHub_125

This test fails when run against AspectJ 1.9.8 with JDT Core 1.9.8.RC3.
It passes when using the latest JDT Core 1.9.9-SNAPSHOT. It sets system
property 'org.aspectj.weaver.openarchives=20', provoking open classpath
JAR file exhaustion when compiling a simple class with AJC, i.e. JARs
are being forcibly closed and automatically re-opened, as soon as they
are needed. Before the JDT Core bugfix, this test causes:

java.lang.NullPointerException
  at ....compiler.batch.ClasspathJmod.getModulesDeclaringPackage

With the bugfix incorporated into AspectJ Tools, the problem is gone.

Note: New test dependency 'io.github.bmuskalla:scoped-system-properties'
helps to test compilation with the temporarily changed global system
property in isolation, saving the environment in a thread-local
variable and later cleanly restoring the original values again. If we
ever switch to parallel test execution, this would otherwise influence
other tests and potentially cause weird side effects. Better safe than
sorry.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tags/V1_9_9
Alexander Kriegisch 2 years ago
parent
commit
0fb70c99cf

+ 11
- 0
tests/bugs198/github_125/Application.java View File

@@ -0,0 +1,11 @@
public class Application {
public static void main(String[] argv) {
System.out.println("Hello world!");
}

static aspect MyAspect {
before(): execution(* Application.main(..)) {
System.out.println("Before advice");
}
}
}

+ 11
- 0
tests/pom.xml View File

@@ -90,6 +90,17 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!--
Used for tests setting system properties, e.g. for AJC, when we need to avoid polluting the global
system properties namespace with settings potentially influencing other tests.
See https://github.com/bmuskalla/scoped-system-properties.
-->
<dependency>
<groupId>io.github.bmuskalla</groupId>
<artifactId>scoped-system-properties</artifactId>
<version>1.1.0</version>
<scope>test</scope>
</dependency>

<!--
The tests need these during runtime, even though no direct usage is in our classes.

+ 12
- 3
tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java View File

@@ -7,6 +7,8 @@
*******************************************************************************/
package org.aspectj.systemtest.ajc198;

import io.bmuskalla.system.properties.PropertyEnvironment;
import io.bmuskalla.system.properties.ScopedSystemProperties;
import junit.framework.Test;
import org.aspectj.testing.XMLBasedAjcTestCase;

@@ -15,9 +17,9 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
*/
public class Bugs198Tests extends XMLBasedAjcTestCase {

public void testGitHub_105() {
runTest("ITD annotation with mandatory parameter via aspectpath");
}
public void testGitHub_105() {
runTest("ITD annotation with mandatory parameter via aspectpath");
}

public void testAnnotationStyleSpecialIfClauses() {
runTest("annotation style A");
@@ -39,6 +41,13 @@ public class Bugs198Tests extends XMLBasedAjcTestCase {
runTest("annotation style negated if");
}

public void testGitHub_125() {
try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) {
env.setProperty("org.aspectj.weaver.openarchives", "20");
runTest("compiler can re-open closed JARs");
}
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Bugs198Tests.class);
}

+ 14
- 0
tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml View File

@@ -153,4 +153,18 @@
</run>
</ajc-test>

<ajc-test dir="bugs198/github_125" title="compiler can re-open closed JARs">
<!--
Here the Java test sets system property org.aspectj.weaver.openarchives to 20 in order to provoke
open JAR limit exhaustion
-->
<compile files="Application.java" options="-1.5" />
<run class="Application">
<stdout>
<line text="Before advice"/>
<line text="Hello world!"/>
</stdout>
</run>
</ajc-test>

</suite>

Loading…
Cancel
Save