GeezerVison is showing github.com — `ClassCastException` in `AnnotatedTypeFactory.getAnnotatedType()` · Issue #4690 · typetools/checker-framework
ClassCastException in AnnotatedTypeFactory.getAnnotatedType() #4690
DescriptionI don't have a self-contained repro, but the issue should be easy to understand. We are seeing the following crash when running the Object Construction Checker:
Exception: java.lang.ClassCastException: org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedIntersectionType cannot be cast to org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedDeclaredType; java.lang.ClassCastException: org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedIntersectionType cannot be cast to org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedDeclaredType
at org.checkerframework.framework.type.AnnotatedTypeFactory.getAnnotatedType(AnnotatedTypeFactory.java:2915)
at org.checkerframework.checker.objectconstruction.ObjectConstructionAnnotatedTypeFactory.getMustCallValue(ObjectConstructionAnnotatedTypeFactory.java:155)
...
It happens at this line:
|
return (AnnotatedDeclaredType) getAnnotatedType((Element) elt); |
And the related code has an interface declaration like this:
public interface Writer extends Closeable, CellSink, ShipperListener {}
So it seems that when calling getAnnotatedType(TypeElement) the result may not always be an AnnotatedDeclaredType.
Sorry again for not having a small test input to reproduce; we can put one together if need be.
/cc @kelloggm @Nargeshdb Activitymsridhar commented on Jun 7, 2021 ContributorAuthor More actions @smillst do you need a full repro for this one? or is the info above enough to reproduce? smillst commented on Jun 9, 2021 @msridhar I'm going to need a full repro. I can't reproduce this. It's fine if it requires the Object Construction Checker. msridhar commented on Jun 11, 2021 ContributorAuthor More actions Ok, managed to get a somewhat simplified example. Here is the code:
import java.io.*;
class Test {
enum BloomType {
NONE,
ROW,
ROWCOL,
ROWPREFIX_FIXED_LENGTH
}
static class Bytes {
static int toInt(byte[] bytes) {
return 0;
}
static String toStringBinary(byte[] bytes) {
return "str";
}
}
static class StoreFileWriter {
BloomType bloomType;
byte[] bloomParam = null;
static boolean isTraceEnabled() {
return true;
}
static void trace(String s) {}
StoreFileWriter(BloomType bloomType, Object path) throws IOException {
if (isTraceEnabled()) {
trace(
"Bloom filter type for "
+ path
+ ": "
+ this.bloomType
+ ", param: "
+ (bloomType == BloomType.ROWPREFIX_FIXED_LENGTH
? Bytes.toInt(bloomParam)
: Bytes.toStringBinary(bloomParam))
+ ", "
+ getClass().getSimpleName());
}
switch (bloomType) {
case ROW:
break;
case ROWCOL:
break;
case ROWPREFIX_FIXED_LENGTH:
break;
default:
throw new IOException(
"Invalid Bloom filter type: " + bloomType + " (ROW or ROWCOL or ROWPREFIX expected)");
}
}
}
}
To reproduce the crash, build the framework from #4687 (at git SHA d8ddc96) and then run ./checker/bin/javac -processor resourceleak Test.java. If we can find a way to repro without using the Resource Leak Checker that would be best, as it is still under review and I can't guarantee it will keep exposing this issue as the code changes.
With this example, getAnnotatedType() gets called with a Symbol$ClassSymbol whose type field is a Type$IntersectionClassType, leading to the exception. smillst commented on Jun 11, 2021 Thanks I can reproduce this now. I think we just have to remove AnnotatedTypeFactory#getAnnotatedType(javax.lang.model.element.TypeElement). Since TypeElement can represent non-declared types contrary to TypeElement's documentation. I'll do that. Reacted by Manu Sridharan
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|