Skip to content

Commit

Permalink
Resource Leak Checker: Add a check to avoid mapping multiple keys to …
Browse files Browse the repository at this point in the history
…a ternary expression for tempVarToTree (typetools#5137)
  • Loading branch information
Nargeshdb authored and wmdietl committed Jun 2, 2022
1 parent c85d606 commit 706ce5e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ protected ResourceLeakAnalysis createFlowAnalysis() {
* @param tree the tree of the expression the tempvar represents
*/
/* package-private */ void addTempVar(LocalVariableNode tmpVar, Tree tree) {
tempVarToTree.put(tmpVar, tree);
if (!tempVarToTree.containsValue(tree)) {
tempVarToTree.put(tmpVar, tree);
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions checker/tests/resourceleak/HDFSReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Handler extends Thread {
boolean running;

static class Call {
boolean isResponseDeferred() {
return true;
}
}

@Override
public void run() {
while (running) {
Call call = null;
try {
if (running) {
continue;
}
} catch (Exception e) {
} finally {
String s = call.isResponseDeferred() ? ", deferred" : "";
}
}
}
}

0 comments on commit 706ce5e

Please sign in to comment.