Skip to content

Commit

Permalink
Fix crash in RLC (typetools#6051)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelloggm authored Jun 21, 2023
1 parent c01aa03 commit 6ca2bf8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,13 @@ && varTrackedInObligations(obligations, (LocalVariableNode) receiver))
mcAnno =
mcTypeFactory.getAnnotatedType(lhs.getElement()).getPrimaryAnnotation(MustCall.class);
}
// if mcAnno is still null, then the declared type must be something other than
// @MustCall (probably @MustCallUnknown). Do nothing in this case: a warning
// about the field will be issued elsewhere (it will be impossible to satisfy its
// obligations!).
if (mcAnno == null) {
return;
}
List<String> mcValues =
AnnotationUtils.getElementValueArray(
mcAnno, mcTypeFactory.getMustCallValueElement(), String.class);
Expand Down
29 changes: 29 additions & 0 deletions checker/tests/resourceleak/Issue6030.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Test case for https://github.com/typetools/checker-framework/issues/6030

import java.util.*;
import org.checkerframework.checker.mustcall.qual.Owning;

public class Issue6030 {

interface CloseableIterator<T> extends Iterator<T>, java.io.Closeable {}

static class MyScanner<T, I extends MyScanner<T, I>> implements CloseableIterator<T> {
@Owning I iterator;

// :: error: missing.creates.mustcall.for
public boolean hasNext() {
if (iterator == null) iterator = createIterator();
return iterator.hasNext();
}

public T next() {
return null;
}

private I createIterator() {
return null;
}

public void close() {}
}
}
15 changes: 15 additions & 0 deletions checker/tests/resourceleak/OwningMCU.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// a test case that @Owning @MustCallUnknown fields do not cause a crash. Of course,
// such fields should never exist. But, better to be safe. Relevant GitHub issue with
// discussion: https://github.com/typetools/checker-framework/issues/6030.

import org.checkerframework.checker.mustcall.qual.*;

public class OwningMCU {

@Owning @MustCallUnknown Object foo;

// :: error: missing.creates.mustcall.for
void test() {
foo = new Object();
}
}

0 comments on commit 6ca2bf8

Please sign in to comment.