NullPointerException in SourceTypeBinding.resolveTypeFor when compiling anonymous inner class with annotated field on Java 25
AspectJ 1.9.25.1 fails with a NullPointerException when compiling code that contains an anonymous inner class with an annotated field when targeting Java 25. The same code compiles successfully with AspectJ 1.9.22.1 and Java 21.
Code:
TestConfig.java
package com.test;
import jakarta.validation.constraints.NotNull;
public class TestConfig {
public void testMethod() {
// Anonymous inner class with annotation - this triggers the bug
Object obj = new Object() {
@NotNull(message = "test message")
String field;
};
System.out.println("Created: " + obj);
}
public static void main(String[] args) {
new TestConfig().testMethod();
System.out.println("Success!");
}
}
**LoggingAspect.java**
package com.test;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class LoggingAspect {
@Before("execution(* com.test.TestConfig.testMethod(..))")
public void logBeforeTestMethod(JoinPoint joinPoint) {
System.out.println(">>> ASPECT TRIGGERED: Before executing " + joinPoint.getSignature());
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.test</groupId>
<artifactId>aspectj-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<aspectj.version>1.9.25.1</aspectj.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>dev.aspectj</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.14.1</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>
<source>25</source>
<target>25</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Steps to Reproduce
1. Create a Maven project with the files above
2. Ensure JAVA_HOME points to Java 25
3. Run mvn clean compile
Expected Behavior
The project should compile successfully and AspectJ should weave the aspect into the target class.
<img width="1453" height="612" alt="Image" src="https://github.com/user-attachments/assets/edb60edf-1cdc-4d04-9645-224550f0726e" />
NullPointerException in SourceTypeBinding.resolveTypeFor when compiling anonymous inner class with annotated field on Java 25
AspectJ 1.9.25.1 fails with a NullPointerException when compiling code that contains an anonymous inner class with an annotated field when targeting Java 25. The same code compiles successfully with AspectJ 1.9.22.1 and Java 21.
Code:
TestConfig.java