Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StubParser assertion failure #375

Closed
GoogleCodeExporter opened this issue Jul 3, 2015 · 8 comments
Closed

StubParser assertion failure #375

GoogleCodeExporter opened this issue Jul 3, 2015 · 8 comments
Assignees
Milestone

Comments

@GoogleCodeExporter
Copy link

> What steps will reproduce the problem?
Run the following 3 commands:
7z x demo-example.7z
cd error-version
$CHECKERFRAMEWORK/checker/bin/javac -AprintErrorStack -processor 
org.checkerframework.checker.guieffect.GuiEffectChecker -cp 
../equinox.jar:../swt-win.jar demo/ImageViewer.java 

> What is the expected output? What do you see instead?
The type-checker should run to completion.  Instead, the StubParser suffers an 
assertion error (see stack trace below).  Even if the fault is with the stub 
libraries, the Checker Framework should issue a human-friendly error message 
without a stack trace.

Is the problem that all supertypes of a given type need to be in the stub file? 
 (If so, that could be fixed by augmenting the stub file, but is that a truly 
necessary requirement?)

error: InvocationTargetException when invoking constructor for class 
org.checkerframework.checker.guieffect.GuiEffectVisitor; Underlying cause: 
java.lang.AssertionError: StubParser: could not find superinterface Drawable 
from type /*DECL*/ Display
  Exception: java.lang.reflect.InvocationTargetException; Stack trace: sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  org.checkerframework.common.basetype.BaseTypeChecker.invokeConstructorFor(BaseTypeChecker.java:174)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:113)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:80)
  org.checkerframework.framework.source.SourceChecker.initChecker(SourceChecker.java:713)
  org.checkerframework.framework.source.SourceChecker.typeProcessingStart(SourceChecker.java:674)
  org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:183)
  com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:681)
  com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:111)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1342)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1296)
  com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
  com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
  com.sun.tools.javac.main.Main.compile(Main.java:523)
  com.sun.tools.javac.main.Main.compile(Main.java:381)
  com.sun.tools.javac.main.Main.compile(Main.java:370)
  com.sun.tools.javac.main.Main.compile(Main.java:361)
  com.sun.tools.javac.Main.compile(Main.java:56)
  com.sun.tools.javac.Main.main(Main.java:42)
  Underlying Exception: java.lang.AssertionError: StubParser: could not find superinterface Drawable from type /*DECL*/ Display; Stack trace: org.checkerframework.framework.stub.StubParser.annotateSupertypes(StubParser.java:454)
  org.checkerframework.framework.stub.StubParser.parseType(StubParser.java:436)
  org.checkerframework.framework.stub.StubParser.parse(StubParser.java:371)
  org.checkerframework.framework.stub.StubParser.parse(StubParser.java:319)
  org.checkerframework.framework.stub.StubParser.parse(StubParser.java:299)
  org.checkerframework.framework.stub.StubParser.parse(StubParser.java:294)
  org.checkerframework.framework.type.AnnotatedTypeFactory.buildIndexTypes(AnnotatedTypeFactory.java:2151)
  org.checkerframework.framework.type.GenericAnnotatedTypeFactory.postInit(GenericAnnotatedTypeFactory.java:148)
  org.checkerframework.checker.guieffect.GuiEffectTypeFactory.<init>(GuiEffectTypeFactory.java:45)
  org.checkerframework.checker.guieffect.GuiEffectVisitor.createTypeFactory(GuiEffectVisitor.java:51)
  org.checkerframework.checker.guieffect.GuiEffectVisitor.createTypeFactory(GuiEffectVisitor.java:32)
  org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:192)
  org.checkerframework.checker.guieffect.GuiEffectVisitor.<init>(GuiEffectVisitor.java:41)
  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  org.checkerframework.common.basetype.BaseTypeChecker.invokeConstructorFor(BaseTypeChecker.java:174)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:113)
  org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:80)
  org.checkerframework.framework.source.SourceChecker.initChecker(SourceChecker.java:713)
  org.checkerframework.framework.source.SourceChecker.typeProcessingStart(SourceChecker.java:674)
  org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:183)
  com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:681)
  com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:111)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1342)
  com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1296)
  com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
  com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
  com.sun.tools.javac.main.Main.compile(Main.java:523)
  com.sun.tools.javac.main.Main.compile(Main.java:381)
  com.sun.tools.javac.main.Main.compile(Main.java:370)
  com.sun.tools.javac.main.Main.compile(Main.java:361)
  com.sun.tools.javac.Main.compile(Main.java:56)
  com.sun.tools.javac.Main.main(Main.java:42)

Original issue reported on code.google.com by michael.ernst@gmail.com on 17 Oct 2014 at 8:41

Attachments:

@GoogleCodeExporter
Copy link
Author

I did a bit of poking around, and shared the results with Mike, who suggested I 
repost them here.

If you instrument annotateSupertypes(...) and findType(...) in StubParser.java, 
you can produce output like the following:

...
Annotating supertypes of Display
    Looking at implements parent Drawable
Searching for type: Drawable
    Checking: Device
Type Drawable not found
error: InvocationTargetException when invoking constructor for class 
org.checkerframework.checker.guieffect.GuiEffectVisitor; Underlying cause: 
java.lang.AssertionError: StubParser: could not find superinterface Drawable 
from type Display
<stack trace>

For clarity, here are the instrumented versions (built off 1.8.0, since I 
wanted to see if the first release with the GUI Effects Checker reproduced this 
error --- it does):

    private void annotateSupertypes(ClassOrInterfaceDeclaration typeDecl, AnnotatedDeclaredType type) {
    System.err.println("Annotating supertypes of "+typeDecl.getName());
        if (typeDecl.getExtends() != null) {
            for (ClassOrInterfaceType superType : typeDecl.getExtends()) {
        System.err.println("    Looking at extension parent "+superType.toString());
                AnnotatedDeclaredType foundType = findType(superType, type.directSuperTypes());
                assert foundType != null : "StubParser: could not find superclass " + superType + " from type " + type;
                if (foundType != null) annotate(foundType, superType);
            }
        }
        if (typeDecl.getImplements() != null) {
            for (ClassOrInterfaceType superType : typeDecl.getImplements()) {
        System.err.println("    Looking at implements parent "+superType.toString());
                AnnotatedDeclaredType foundType = findType(superType, type.directSuperTypes());
                // TODO: Java 7 added a few AutoCloseable superinterfaces to classes.
                // We specify those as superinterfaces in the jdk.astub file. Let's ignore
                // this addition to be compatible with Java 6.
                assert foundType != null || (superType.toString().equals("AutoCloseable") || superType.toString().equals("java.io.Closeable") || superType.toString().equals("Closeable")) :
                    "StubParser: could not find superinterface " + superType + " from type " + type;
                if (foundType != null) annotate(foundType, superType);
            }
        }
    }

    private AnnotatedDeclaredType findType(ClassOrInterfaceType type, List<AnnotatedDeclaredType> types) {
        String typeString = type.getName();
    System.err.println("Searching for type: "+typeString);
        for (AnnotatedDeclaredType superType : types) {
        System.err.println("    Checking: "+superType.getUnderlyingType().asElement().getSimpleName());
            if (superType.getUnderlyingType().asElement().getSimpleName().contentEquals(typeString))
                return superType;
        }
        stubWarning("Type " + typeString + " not found");
    System.err.println("Type " + typeString + " not found");
        if (debugStubParser)
            for (AnnotatedDeclaredType superType : types)
                stubDebug(String.format("  %s%n", superType));
        return null;
    }

It looks like when annotateSupertypes gets to annotating Display, things go 
fine for the parent class (Device).  Then when going through its interfaces, it 
finds Drawable in the list of interfaces implemented (this is inherited from 
the explicit 'implements' clause on Device, not on the declaration for Display 
itself).  Then it tries to find this in the results of 
type.getDirectSupertypes(), which includes only the parent class Device, not 
the implemented interface.

Original comment by colin.s....@gmail.com on 20 Oct 2014 at 3:47

@GoogleCodeExporter
Copy link
Author

Oh, I also tried explicitly adding Drawable to the stub file as Mike wondered 
about, with no change.

Original comment by colin.s....@gmail.com on 20 Oct 2014 at 3:49

@GoogleCodeExporter
Copy link
Author

Oh, I figured out what's wrong.  In the current stub file, the declaration of 
Display is:

@UIType class Display implements Drawable { ...

which doesn't actually match the declaration in SWT.  Once I fixed it to match 
SWT and rebuilt the checker framework, the example runs:

@UIType class Display extends Device {...



Now the output from the example is:
...
Annotating supertypes of Pattern
demo/ImageViewer.java:30: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        shell.setLayout(new GridLayout(4, false));
                       ^
demo/ImageViewer.java:33: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        button.setText("View Next");
                      ^
demo/ImageViewer.java:34: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        button.addSelectionListener(new NonThreadSelectionAdapter());
                                   ^
demo/ImageViewer.java:37: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        fastbutton.setText("Fast Loading");
                          ^
demo/ImageViewer.java:38: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        fastbutton.addSelectionListener(new NewThreadSelectionAdapter());
                                       ^
demo/ImageViewer.java:44: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        datebutton.setImage(buttonImage);
                           ^
demo/ImageViewer.java:45: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        datebutton.addSelectionListener(new DateSelectionAdapter());
                                       ^
demo/ImageViewer.java:62: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        sc.setLayoutData(layoutData);
                        ^
demo/ImageViewer.java:65: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        imgLabel.setImage(image);
                         ^
demo/ImageViewer.java:66: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        imgLabel.setSize(imgLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                        ^
demo/ImageViewer.java:66: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        imgLabel.setSize(imgLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                                             ^
demo/ImageViewer.java:67: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        sc.setContent(imgLabel);
                     ^
demo/ImageViewer.java:70: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        shell.setSize(1024, 768);
                     ^
demo/ImageViewer.java:71: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        shell.open();
                  ^
demo/ImageViewer.java:73: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
            if (!display.readAndDispatch())
                                        ^
demo/ImageViewer.java:74: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
                display.sleep();
                             ^
demo/ImageViewer.java:77: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        display.dispose();
                       ^
demo/ImageViewer.java:87: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
                .setText("                                                            ");
                        ^
demo/ImageViewer.java:97: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
        imgLabel.setImage(image);
                         ^
demo/ImageViewer.java:100: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
    static class NonThreadSelectionAdapter extends SelectionAdapter {
           ^
demo/ImageViewer.java:108: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
    static class DateSelectionAdapter extends SelectionAdapter {
           ^
demo/ImageViewer.java:113: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
            dateLabel.setText("Time: " + dt.toString());
                             ^
demo/ImageViewer.java:117: error: [call.invalid.ui] Calling a method with 
UIEffect effect from a context limited to SafeEffect effects.
    static class NewThreadSelectionAdapter extends SelectionAdapter {
           ^
23 errors
sliver:error-version csgordon$ 



Feature suggestion for checker developers: A flag that performs consistency 
checks on the stub file, comparing declarations to the actual classpath 
contents.

Original comment by colin.s....@gmail.com on 20 Oct 2014 at 3:59

@GoogleCodeExporter
Copy link
Author

Fixed in 9498:935f06e19430

Original comment by colin.s....@gmail.com on 14 Jun 2015 at 7:26

  • Changed state: Pushed

@GoogleCodeExporter
Copy link
Author

Colin, thanks for eliminating this particular assertion failure.
I'm not sure this addresses the bug, though.  The initial report says:

"Even if the fault is with the stub libraries, the Checker Framework should 
issue a human-friendly error message without a stack trace."

and that is along the lines of your suggestion "Feature suggestion for checker 
developers: A flag that performs consistency checks on the stub file, comparing 
declarations to the actual classpath contents."  That's the real content of 
this issue:  The StubParser should never fail its assertions, even if the stub 
libraries contain an error.

Original comment by michael.ernst@gmail.com on 14 Jun 2015 at 9:16

@GoogleCodeExporter
Copy link
Author

Original comment by colin.s....@gmail.com on 16 Jun 2015 at 4:30

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

Original comment by colin.s....@gmail.com on 16 Jun 2015 at 4:30

@mernst
Copy link
Member

mernst commented Aug 13, 2017

Fixed by 8997a34.

@mernst mernst closed this as completed Aug 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants