Skip to content

Commit

Permalink
Fix for unique.leaked warning on constructors (Feature request typeto…
Browse files Browse the repository at this point in the history
…ols#3313) using .astub files, with test cases
  • Loading branch information
aditya3434 committed May 28, 2020
1 parent 60354d3 commit 7794ac9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Expand Up @@ -23,7 +23,6 @@
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType;
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypesUtils;

/**
* This visitor ensures that every constructor whose result is annotated as {@literal @}Unique does
Expand Down Expand Up @@ -71,8 +70,7 @@ public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
// Check if a call to super() might create an alias: that
// happens when the parent's respective constructor is not @Unique.
AnnotatedTypeMirror superResult = atypeFactory.getAnnotatedType(node);
if ((!superResult.hasAnnotation(Unique.class))
&& (!TypesUtils.isObject(superResult.getUnderlyingType()))) {
if (!superResult.hasAnnotation(Unique.class)) {
checker.reportError(node, "unique.leaked");
}
} else {
Expand Down Expand Up @@ -257,8 +255,7 @@ protected void checkThisOrSuperConstructorCall(
// Check if a call to super() might create an alias: that
// happens when the parent's respective constructor is not @Unique.
AnnotatedTypeMirror superResult = atypeFactory.getAnnotatedType(superCall);
if ((!superResult.hasAnnotation(Unique.class))
&& (!TypesUtils.isObject(superResult.getUnderlyingType()))) {
if (!superResult.hasAnnotation(Unique.class)) {
checker.reportError(superCall, "unique.leaked");
}
}
Expand Down
@@ -0,0 +1,7 @@
import org.checkerframework.common.aliasing.qual.*;

package java.lang;

class Object {
@Unique Object();
}
16 changes: 16 additions & 0 deletions framework/tests/aliasing/UniqueConstructorTest.java
@@ -0,0 +1,16 @@
import org.checkerframework.common.aliasing.qual.Unique;

class ParentUniqueClass{

// No need for @SuppressWarnings()
@Unique ParentUniqueClass(){
// Doesn't raise unique.leaked error since it's a parent class (top of heirarchy)
}
}

class ChildUniqueClass extends ParentUniqueClass {

@Unique ChildUniqueClass(){
// Doesn't raise unique.leaked error since its parent is @Unique
}
}

0 comments on commit 7794ac9

Please sign in to comment.