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

Handle jaif for constructor with empty ASTPath #292

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/checkers/inference/util/ASTPathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public static ASTRecord getASTRecordForPath(final AnnotatedTypeFactory typeFacto
* this class.
*/
public static ASTRecord getConstructorRecord(ASTRecord classRecord) {
return new ASTRecord(classRecord.ast, classRecord.className, AFU_CONSTRUCTOR_ID, null, ASTPath.empty());
return new ASTRecord(classRecord.ast, classRecord.className, AFU_CONSTRUCTOR_ID, null, getMethodTypeASTPath());
}

public static ASTPath getMethodTypeASTPath() {
return ASTPath.empty().extend(new ASTPath.ASTEntry(Tree.Kind.METHOD, ASTPath.TYPE, null));
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/checkers/inference/util/JaifBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ private void buildClassEntries() {
// TODO: this is not a feature but a workaround of a bug:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is just a hacky work-around.
I think it would be better to fix all the places that incorrectly have an empty ASTPath. Instead of a silent continue here, we should raise an error when we still find an empty ASTPath.
Also note the duplication between the change here and the one above. Do we really need both? If so, maybe the getConstructorRecord method should be called in more places?

As discussed, please first add a test case to make sure we're fixing this error.

// We should create a non-empty correct ASTPath for constructor
if (astRecord.astPath.equals(ASTPath.empty())) {
continue;
if (astRecord.methodName != null && astRecord.methodName.contains("<init>")) {
astRecord = new ASTRecord(astRecord.ast, astRecord.className,
astRecord.methodName, astRecord.varName, ASTPathUtil.getMethodTypeASTPath());
} else {
continue;
}
}

memberRecords.entries.add(new RecordValue(astRecord.astPath,annotation));
Expand Down