typetools / typetools/checker-framework

`ClassCastException` in `AnnotatedTypeFactory.getAnnotatedType()`

Open
#4,690 4 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

crash
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

I 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:

https://github.com/typetools/checker-framework/blob/061fb741c13cb202dda82ef17ad61ca522a4736b/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java#L2916

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.