[Bug]: `<nulltype> cannot be found` when calling `nullType.isEnum()`
- Dominant language
- Java
- Stars
- 2k
- Forks
- 392
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 36
Description
### Describe the bug
This was discovered through this issue #5412. It does not crash in noclasspath mode, where it returns `false`.
### Source code you are trying to analyze/transform
_No response_
### Source code for your Spoon processing
```Java
import org.junit.jupiter.api.Test;
import spoon.Launcher;
import spoon.reflect.CtModel;
import spoon.reflect.code.CtNewArray;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtField;
import spoon.reflect.reference.CtArrayTypeReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.compiler.VirtualFile;
import static org.junit.jupiter.api.Assertions.*;
class TestSpoon {
@Test
void testNullLiteralIsEnum() {
// contract: even for the the methods should work
Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(false);
launcher.addInputResource(new VirtualFile("public class Example {}", "Example"));
CtModel ctModel = launcher.buildModel();
CtTypeReference nullType = ctModel.getRootPackage().getFactory().Type().nullType();
assertFalse(nullType.isEnum());
}
}
```
### Actual output
```Java
spoon.support.SpoonClassNotFoundException: cannot be found
at spoon.support.reflect.reference.CtTypeReferenceImpl.isEnum(CtTypeReferenceImpl.java:621)
```
### Expected output
_No response_
### Spoon Version
10.4.0
### JVM Version
openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12) OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)
### What operating system are you using?
Windows 10
Contributor guide
Research direction
Start at spoon.support.reflect.reference.CtTypeReferenceImpl.java:621, where isEnum() is reported to fail for the null type. Reproduce the issue with the supplied Launcher and nullType() test, then verify that calling isEnum() returns false without throwing SpoonClassNotFoundException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100