Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2020-01-03 13:54:21 -0500
committerStephan Herrmann2020-01-03 16:50:29 -0500
commit16ebd125b67e3fb21848f1cf93e610e6b19bf2c0 (patch)
tree9aa1a7bdc114da17fb06ab6edc04dc6651ce96e4
parent97609bfc7e97c6f6ae7ba958f656e2efd47c7fce (diff)
downloadeclipse.jdt.core-I20200105-0600.tar.gz
eclipse.jdt.core-I20200105-0600.tar.xz
eclipse.jdt.core-I20200105-0600.zip
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java34
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java17
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java21
3 files changed, 66 insertions, 6 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
index 18b81e4283..a5fe67e780 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
@@ -6366,4 +6366,38 @@ public void testBug527761_neg() {
"----------\n",
options);
}
+// regression caused by Bug 527761
+public void testBug558759() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses generics
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR);
+ String ySource =
+ "public class Y {\n" +
+ " class YInner extends X<I> {}\n" +
+ "}\n";
+ runConformTest(
+ new String[] {
+ "I.java",
+ "import java.io.Closeable;\n" +
+ "public interface I extends Closeable {\n" +
+ " interface Location {}\n" +
+ " void m(Location l);\n" +
+ "}\n",
+ "X0.java",
+ "public abstract class X0<T extends I> implements I {\n" +
+ " public void close() {}\n" +
+ "}\n",
+ "X.java",
+ "public class X<T extends I> extends X0<T> implements I {\n" +
+ " public void m(Location l) {}\n" +
+ "}\n",
+ "Y.java",
+ ySource
+ },
+ options);
+ runConformTest(false,
+ new String[] { "Y.java", ySource },
+ "", "", "", null);
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
index 15d85ca80f..67e1db992a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java
@@ -2104,18 +2104,23 @@ protected int applyCloseableClassWhitelists(CompilerOptions options) {
if (options.analyseResourceLeaks) {
ReferenceBinding mySuper = this.superclass();
if (mySuper != null && mySuper.id != TypeIds.T_JavaLangObject) {
- for (MethodBinding methodBinding : unResolvedMethods()) {
- if (CharOperation.equals(methodBinding.selector, TypeConstants.CLOSE)
- && methodBinding.parameters == Binding.NO_PARAMETERS) {
- return 0;
- }
- }
+ if (hasMethodWithNumArgs(TypeConstants.CLOSE, 0))
+ return 0; // close methods indicates: class may need more closing than super
return mySuper.applyCloseableClassWhitelists(options);
}
}
return 0;
}
+protected boolean hasMethodWithNumArgs(char[] selector, int numArgs) {
+ for (MethodBinding methodBinding : unResolvedMethods()) {
+ if (CharOperation.equals(methodBinding.selector, TypeConstants.CLOSE)
+ && methodBinding.parameters.length == numArgs) {
+ return true;
+ }
+ }
+ return false;
+}
/*
* If a type - known to be a Closeable - is mentioned in one of our white lists
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index f2eb5efa0e..a8f9b01261 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -2268,6 +2268,27 @@ boolean hasNonNullDefaultFor(int location, int sourceStart) {
}
@Override
+protected boolean hasMethodWithNumArgs(char[] selector, int numArgs) {
+ if ((this.tagBits & TagBits.AreMethodsComplete) != 0)
+ return super.hasMethodWithNumArgs(selector, numArgs);
+ // otherwise don't trigger unResolvedMethods() which would actually resolve!
+ if (this.scope != null) {
+ for (AbstractMethodDeclaration method : this.scope.referenceContext.methods) {
+ if (CharOperation.equals(method.selector, TypeConstants.CLOSE)) {
+ if (numArgs == 0) {
+ if (method.arguments == null)
+ return true;
+ } else {
+ if (method.arguments != null && method.arguments.length == numArgs)
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+@Override
public AnnotationHolder retrieveAnnotationHolder(Binding binding, boolean forceInitialization) {
if (!isPrototype())
return this.prototype.retrieveAnnotationHolder(binding, forceInitialization);

Back to the top