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

Bug when inserting upper bound of class type variable #154

Open
topnessman opened this issue Jan 14, 2018 · 3 comments
Open

Bug when inserting upper bound of class type variable #154

topnessman opened this issue Jan 14, 2018 · 3 comments
Assignees

Comments

@topnessman
Copy link

Testcase:
Bound.java

package bug;

public class Bound {}

Bug.java

package bug;

public class Bug<T extends Bound> {}

Jaif File: 0.jaif

package qual:
  annotation @A:

package bug:
class Bug:
insert-annotation Class.typeParameter 0: @qual.A
insert-annotation Class.typeParameter 0, TypeParameter.bound 0: @qual.A

method <init>()V:
insert-annotation Method.type: @qual.A

Command to run:

../annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source -v -d . testinput/inference/bug/0.jaif testinput/inference/bug/Bug.java testinput/inference/bug/Bound.java

Console Output:

Warning: IndexFileSpecification did not find classfile for: bug.Bug
Read 4 annotations from testinput/inference/bug/0.jaif
Processing testinput/inference/bug/Bug.java
Parsed testinput/inference/bug/Bug.java
Exception in thread "main" java.lang.Error
	at annotator.find.Insertions$TypeTree.javacTypeToType(Insertions.java:1357)
	at annotator.find.Insertions$TypeTree.javacTypeToType(Insertions.java:1326)
	at annotator.find.Insertions$TypeTree.javacTypeToType(Insertions.java:1309)
	at annotator.find.Insertions$TypeTree.fromJavacType(Insertions.java:1289)
	at annotator.find.Insertions.organizeTypedInsertions(Insertions.java:581)
	at annotator.find.Insertions.forClass(Insertions.java:148)
	at annotator.find.Insertions.forOuterClass(Insertions.java:128)
	at annotator.find.TreeFinder.getPositions(TreeFinder.java:1872)
	at annotator.Main.main(Main.java:708)

Expected: no errors
Actual: Got exception

I changed the file order:

../annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source -v -d . testinput/inference/bug/0.jaif testinput/inference/bug/Bound.java testinput/inference/bug/Bug.java

Console Output:

Warning: IndexFileSpecification did not find classfile for: bug.Bug
Read 4 annotations from testinput/inference/bug/0.jaif
Processing testinput/inference/bug/Bound.java
Parsed testinput/inference/bug/Bound.java
getPositions returned 0 positions in tree for testinput/inference/bug/Bound.java
Writing ./bug/Bound.java
Processing testinput/inference/bug/Bug.java
Parsed testinput/inference/bug/Bug.java
getPositions returned 2 positions in tree for testinput/inference/bug/Bug.java
..Writing ./bug/Bug.java

Expected: no errors
Bound.java

package bug;

public class Bound {}

Bug.java

package bug;
import qual.A;

public class Bug<@A T extends @A Bound> {}

Actual: no errors
Insertion result is the same as expected.

If I change T extends Bound to T extends Object, insertion result is as expected and there is not error.

After running the second command(which is successful), I ran the first command(which failed before) but the result was as expected and there wasn't error anymore. I tried removing Bound.java from output directory, and then ran the first command again(the one that had error). This time, I got the same failure result again.
Reasoning: it looks like java source file of class type variable's upper bound must exist in output directory to make the whole insertion succeed. The first command succeeded because the second command output Bound.java into the output directory, and it was picked up when I ran the first command right after second command. But this would cause trivial ordering when inserting annotation.

@topnessman
Copy link
Author

topnessman commented Jan 14, 2018

One strange thing is:
if I change jaif file to:

package qual:
  annotation @A:

package bug:
class Bug:
insert-annotation Class.typeParameter 0: @qual.A
insert-annotation Class.typeParameter 0, TypeParameter.bound 0: @qual.A
// Removed the constructor method type insertion statement

No matter I ran:

../annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source -v -d . testinput/inference/bug/0.jaif testinput/inference/bug/Bound.java testinput/inference/bug/Bug.java

or

../annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source -v -d . testinput/inference/bug/0.jaif testinput/inference/bug/Bug.java testinput/inference/bug/Bound.java

I got the same result:
Expected:
Bound.java

package bug;

public class Bound {}

Bug.java

package bug;
import qual.A;

public class Bug<@A T extends @A Bound> {}

Actual:

Warning: IndexFileSpecification did not find classfile for: bug.Bug
Read 2 annotations from testinput/inference/bug/0.jaif
Processing testinput/inference/bug/Bug.java
Parsed testinput/inference/bug/Bug.java
getPositions returned 2 positions in tree for testinput/inference/bug/Bug.java
..Writing ./bug/Bug.java
Processing testinput/inference/bug/Bound.java
Parsed testinput/inference/bug/Bound.java
getPositions returned 0 positions in tree for testinput/inference/bug/Bound.java
Writing ./bug/Bound.java
Warning: IndexFileSpecification did not find classfile for: bug.Bug
Read 2 annotations from testinput/inference/bug/0.jaif
Processing testinput/inference/bug/Bound.java
Parsed testinput/inference/bug/Bound.java
getPositions returned 0 positions in tree for testinput/inference/bug/Bound.java
Writing ./bug/Bound.java
Processing testinput/inference/bug/Bug.java
Parsed testinput/inference/bug/Bug.java
getPositions returned 2 positions in tree for testinput/inference/bug/Bug.java
..Writing ./bug/Bug.java

and the insertion results are the same as expected.

topnessman added a commit to topnessman/immutability that referenced this issue Jan 19, 2018
Needs this PR is merged, still: https://github.com/opprop/checker-
framework-inference/pull/129
This fix also triggered a bug in annotation-tools:
typetools/annotation-tools#154
@topnessman
Copy link
Author

@mernst @wmdietl

@wmdietl wmdietl self-assigned this Mar 1, 2018
@wmdietl
Copy link
Member

wmdietl commented Mar 12, 2018

@topnessman This error looks very similar to #155. Can you try whether the fix in #160 also fixes this issue?

@wmdietl wmdietl assigned topnessman and unassigned wmdietl Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants