Open GoogleCodeExporter opened 9 years ago
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
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
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
Original issue reported on code.google.com by
michael.ernst@gmail.com
on 17 Oct 2014 at 8:41Attachments: