compatibility issues to bridge differences between 3.8 M2-M3 regarding:
- bug 360328: [compiler][null] detect null problems in nested
- bug 349326: [1.7] new warning for missing
diff --git a/contrib/org.eclipse.objectteams.jdt.nullity/plugin.xml b/contrib/org.eclipse.objectteams.jdt.nullity/plugin.xml
index 61266d9..f9324f2 100644
--- a/contrib/org.eclipse.objectteams.jdt.nullity/plugin.xml
+++ b/contrib/org.eclipse.objectteams.jdt.nullity/plugin.xml
@@ -19,6 +19,11 @@
class="org.eclipse.objectteams.internal.jdt.nullity.DOMAdaptation"
icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
</team>
+ <team
+ activation="NONE"
+ class="org.eclipse.objectteams.internal.jdt.nullity.Compatibility"
+ icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
+ </team>
</aspectBinding>
</extension>
<extension
diff --git a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/Compatibility.java b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/Compatibility.java
new file mode 100644
index 0000000..490f683
--- /dev/null
+++ b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/Compatibility.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GK Software AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stephan Herrmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.objectteams.internal.jdt.nullity;
+
+import org.eclipse.jdt.internal.compiler.ast.Expression;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
+import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
+
+import base org.eclipse.jdt.internal.compiler.ast.FakedTrackingVariable;
+
+/**
+ * Fassade to a class that was introduced in JDT/Core 3.8M3.
+ *
+ * @author stephan
+ */
+@SuppressWarnings("restriction")
+public team class Compatibility {
+
+ protected class FakedTrackingVariable implements IFakedTrackingVariable playedBy FakedTrackingVariable {
+ FakedTrackingVariable getCloseTrackingVariable(Expression expression)
+ -> FakedTrackingVariable getCloseTrackingVariable(Expression expression);
+
+ @SuppressWarnings("decapsulation")
+ protected MethodScope methodScope() -> get MethodScope methodScope;
+
+ void markClosedInNestedMethod() -> void markClosedInNestedMethod();
+ }
+
+ public IFakedTrackingVariable getCloseTrackingVariable(Expression expression) {
+ return FakedTrackingVariable.getCloseTrackingVariable(expression);
+ }
+
+ // delegate to new method in BlockScope:
+ public void removeTrackingVar(BlockScope currentScope, IFakedTrackingVariable trackingVariable) {
+ currentScope.removeTrackingVar((FakedTrackingVariable)trackingVariable);
+ }
+
+}
diff --git a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java
index fdc4fcf..1ec292e 100644
--- a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java
+++ b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/CompilerAdaptation.java
@@ -304,6 +304,7 @@
@SuppressWarnings({ "inferredcallout", "basecall", "decapsulation" })
callin FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
+ MethodScope methodScope = currentScope.methodScope();
if (this.expression != null) {
// workaround for Bug 354480 - VerifyError due to bogus lowering in inferred callout-to-field
org.eclipse.jdt.internal.compiler.lookup.BlockScope blockScope = currentScope;
@@ -313,9 +314,22 @@
}
if (flowInfo.reachMode() == FlowInfo.REACHABLE)
checkAgainstNullAnnotation(currentScope, this.expression.nullStatus(flowInfo));
+ try {
+ Compatibility compatibility = new Compatibility();
+ IFakedTrackingVariable trackingVariable = compatibility.getCloseTrackingVariable(this.expression);
+ if (trackingVariable != null) {
+ if (methodScope != trackingVariable.methodScope())
+ trackingVariable.markClosedInNestedMethod();
+ // don't report issues concerning this local, since by returning
+ // the method passes the responsibility to the caller:
+ compatibility.removeTrackingVar(currentScope, trackingVariable);
+ }
+ } catch (Throwable e) {
+ // nop, compatibility with older JDT/Core versions
+ }
}
this.initStateIndex =
- currentScope.methodScope().recordInitializationStates(flowInfo);
+ methodScope.recordInitializationStates(flowInfo);
// compute the return sequence (running the finally blocks)
FlowContext traversedContext = flowContext;
int subCount = 0;
@@ -352,14 +366,14 @@
}
saveValueNeeded = true;
this.initStateIndex =
- currentScope.methodScope().recordInitializationStates(flowInfo);
+ methodScope.recordInitializationStates(flowInfo);
}
}
} else if (traversedContext instanceof InitializationFlowContext) {
currentScope.problemReporter().cannotReturnInInitializer(this);
return FlowInfo.DEAD_END;
}
- } while ((traversedContext = traversedContext.parent) != null);
+ } while ((traversedContext = getLocalParent(traversedContext)) != null);
// resize subroutines
if ((this.subroutines != null) && (subCount != this.subroutines.length)) {
@@ -377,8 +391,18 @@
this.expression.bits |= ASTNode.IsReturnedValue;
}
}
+ try {
+ currentScope.checkUnclosedCloseables(flowInfo, this, currentScope);
+ } catch (Throwable e) {
+ // nop, compatibility with older JDT/Core versions.
+ }
return FlowInfo.DEAD_END;
- }
+ }
+ FlowContext getLocalParent(FlowContext flowContext) {
+ if (flowContext.associatedNode instanceof org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration || flowContext.associatedNode instanceof TypeDeclaration)
+ return null;
+ return flowContext.parent;
+ }
void checkAgainstNullAnnotation(BlockScope scope, int nullStatus) {
if (nullStatus != FlowInfo.NON_NULL) {
@@ -521,6 +545,10 @@
void analyseArgumentNullity(FlowInfo info)
<- before void analyseCode(ClassScope classScope, FlowContext initializationContext, FlowInfo info)
with { info <- info }
+ // compatibility<= 3.8M2
+ void analyseArgumentNullity(FlowInfo info)
+ <- before void analyseCode(ClassScope classScope, InitializationFlowContext initializationContext, FlowInfo info)
+ with { info <- info }
}
protected class ConstructorDeclaration extends AbstractMethodDeclaration playedBy ConstructorDeclaration {
@@ -1065,6 +1093,9 @@
ProblemReporter problemReporter() -> ProblemReporter problemReporter();
MethodScope methodScope() -> MethodScope methodScope();
LookupEnvironment environment() -> LookupEnvironment environment();
+ // method introduced in 3.8M3:
+ void checkUnclosedCloseables(FlowInfo flowInfo, ASTNode location, BlockScope locationScope)
+ -> void checkUnclosedCloseables(FlowInfo flowInfo, ASTNode location, BlockScope locationScope);
}
// ---- Handling sub-classes of FlowContext that perform deferred null checking: ----
diff --git a/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/IFakedTrackingVariable.java b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/IFakedTrackingVariable.java
new file mode 100644
index 0000000..8b1f099
--- /dev/null
+++ b/contrib/org.eclipse.objectteams.jdt.nullity/src/org/eclipse/objectteams/internal/jdt/nullity/IFakedTrackingVariable.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GK Software AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stephan Herrmann - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.objectteams.internal.jdt.nullity;
+
+import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
+
+/**
+ * Fassade to a class that was introduced in JDT/Core for 3.8M3.
+ *
+ * @author stephan
+ */
+@SuppressWarnings("restriction")
+public interface IFakedTrackingVariable {
+
+ MethodScope methodScope();
+
+ void markClosedInNestedMethod();
+
+}