GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `ClassCastException` in `AnnotatedTypeFactory.getAnnotatedType()` · Issue #4690 · typetools/checker-framework

ClassCastException in AnnotatedTypeFactory.getAnnotatedType() #4690

New issue
Copy link
New issue
Copy link
Closed
#8302
Closed
ClassCastException in AnnotatedTypeFactory.getAnnotatedType()#4690
#8302
Copy link
Assignees
smillst
Labels
crash

Description

@msridhar
msridhar
opened on May 26, 2021
Issue body actions

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:

checker-framework/framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java

Line 2916 in 061fb74

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

Activity

  1. msridhar
    added
    bug
    on May 26, 2021
  2. smillst
    added
    crash
    and removed
    bug
    on Jun 1, 2021
  3. smillst
    self-assigned this
    on Jun 1, 2021
  4. msridhar commented on Jun 7, 2021

    @msridhar
    msridhar
    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?

  5. smillst commented on Jun 9, 2021

    @smillst
    smillst
    on Jun 9, 2021
    Member
    More actions

    @msridhar I'm going to need a full repro. I can't reproduce this. It's fine if it requires the Object Construction Checker.

  6. smillst
    assigned
    msridhar
    and unassigned
    smillst
    on Jun 9, 2021
  7. msridhar commented on Jun 11, 2021

    @msridhar
    msridhar
    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.

  8. msridhar
    assigned
    smillst
    and unassigned
    msridhar
    on Jun 11, 2021
  9. smillst commented on Jun 11, 2021

    @smillst
    smillst
    on Jun 11, 2021
    Member
    More actions

    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
  10. smillst
    closed this as completedin #8302on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @smillst
    smillst

Labels

crash

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.