Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 439298

Summary: [null] "Missing code implementation in the compiler" when using @NonNullByDefault in package-info.java
Product: [Eclipse Project] JDT Reporter: Mickaël Vera <vera.mickael>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: daniel_megert, jarthana, manoj.palat, srikanth_sankaran
Version: 4.4Flags: jarthana: review+
Target Milestone: 4.4.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
just compile this project, the error should raise
none
patch for issue in comment 4 none

Description Mickaël Vera CLA 2014-07-09 19:33:17 EDT
Created attachment 244949 [details]
just compile this project, the error should raise

The compiler raises the error "Missing code implementation in the compiler" when compiling the small project attached to this report.

If I remove the line @NonNullByDefault in package-info.java the problem disappears.

I use:
jdk 1.8 u5 x64
eclipse 4.4 RC3 x64

compiler compliance level is 1.8

I added plugins checkstyle and findbugs.

I did activate a lot of options in warning/errors of the compiler.

Regards,
Mickaël
Comment 1 Mickaël Vera CLA 2014-07-09 19:44:27 EDT
I imported the project attached in a new workspace and the problem occurred only when I activated null pointer analysis:

Project > right click > properties > Java Compiler > Errors/Warnings > Configure Workspace Settings > Null Analysis

Then check "Enable annotation-based null analysis"
Comment 2 Stephan Herrmann CLA 2014-08-02 07:35:06 EDT
I can reproduce in R4_4, but not in HEAD.

Specifically, the bug appears fixed since the fix for bug 438179.

To understand whether that fix really resolves or just hides the problem in this bug I'm using this minimal repro:

//---
import org.eclipse.jdt.annotation.*;

class R<T> {
	R(@Nullable T t) {}
}
class A {}
@NonNullByDefault
public class Extract {
	R<A> test() {
		return new R<A>(null);
	}
}
//---
Comment 3 Stephan Herrmann CLA 2014-08-02 07:44:38 EDT
Variant of the code:

Avoid @NonNullByDefault:

//---
import org.eclipse.jdt.annotation.*;

class R<T> {
	R(@Nullable T t) {}
}
class A {}
public class Extract {
	R<A> test() {
		return new R<@NonNull A>(null);
	}
}
//---

==>> Also: broken prior to bug 438179, fixed with bug 438179.

==>> Not an issue of nullness defaults.
Comment 4 Stephan Herrmann CLA 2014-08-02 07:47:10 EDT
Another variant:

Remove warning "Redundant specification of type arguments <A>"
(shouldn't we suppress this warning if the type argument brings new type annotations into the equation?):

//---
import org.eclipse.jdt.annotation.*;

class R<T> {
    R(@Nullable T t) {}
}
class A {}
public class Extract {
    R<@NonNull A> test() {
        return new R<>(null);
    }
}
//---

==>> OK after bug 438179, before that fix:

java.lang.IllegalArgumentException: Type doesn't have its own method?
    at org.eclipse.jdt.internal.compiler.lookup.SyntheticFactoryMethodBinding.applyTypeArgumentsOnConstructor(SyntheticFactoryMethodBinding.java:40)
    at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.registerInferenceContext(AllocationExpression.java:776)
    at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.inferInvocationType(InferenceContext18.java:536)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.inferInvocationType(Scope.java:5150)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getStaticFactory(Scope.java:5068)
    at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.inferElidedTypes(AllocationExpression.java:581)
    at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.resolvePart2(AllocationExpression.java:497)
    at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.resolveType(AllocationExpression.java:487)

Need to investigate relation to bug 440764 ...
Comment 5 Stephan Herrmann CLA 2014-08-02 07:58:34 EDT
Created attachment 245658 [details]
patch for issue in comment 4

This patch adds extra safety to avoid the IllegalArgumentException.

This patch is not strictly needed for the given snippet after the fix for bug 438179, but may be safer to add anyway.
Comment 6 Stephan Herrmann CLA 2014-08-02 08:51:44 EDT
Problems from comment 2 and comment 3 are indeed duplicates of bug 438179.

Problem from comment 4 is a duplicate of bug 440764.


I still have a patch under test that:
- adds all three tests from this bug
- applies the patch from comment 5 to fully avoid the original problem

To see the patch in effect you'd have to rewind to a state prior to bug 438179.
Comment 7 Stephan Herrmann CLA 2014-08-02 09:37:54 EDT
Released for 4.5 M1 via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=caa8e2c381e9b7346f8392e15cd0656885bb751e

Proposing for 4.4.1, because:

- in 4.4 the IAE can still be observed, in fact even if bug 438179 would be backported, we cannot fully rule out that it pops up in some other situation

- the fix is small and directly acknowledges the fact that a MethodBinding can always be a ProblemMethodBinding.
Comment 8 Stephan Herrmann CLA 2014-08-02 09:55:16 EDT
(In reply to Stephan Herrmann from comment #7)
> - in 4.4 the IAE can still be observed, in fact even if bug 438179 would be
> backported, we cannot fully rule out that it pops up in some other situation

Correction: not IAE but "Missing code implementation in the compiler".
(The IAE is being handled via bug 440764).
Comment 9 Stephan Herrmann CLA 2014-08-02 10:03:08 EDT
Since I confused the parts of bug 438179 to which this relates, let me restate the rationale for backporting:

- in 4.4 the bogus compiler error "Missing code implementation in the compiler" can still be observed, in fact even if bug 438179 would be backported, we cannot fully rule out that it pops up in some other situation

- the fix is small and directly acknowledges a ProblemReason that had been added during 4.4 (invalidMethod already handles this reason, but invalidConstructor lacked that case).

Sorry for the confusion :-/
Comment 10 Jay Arthanareeswaran CLA 2014-08-04 09:33:01 EDT
+1 for back porting
Comment 12 Manoj N Palat CLA 2014-08-28 02:32:04 EDT
Verified for Eclipse Luna SR1 4.4.1 Build id: M20140827-0800
Comment 13 Manoj N Palat CLA 2015-01-28 02:25:06 EST
Verified for Eclipse Mars 4.5 M5 Build id: I20150126-2000