Bug 468853 - NPE in Compiler.restoreAptProblems
Summary: NPE in Compiler.restoreAptProblems
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: 4.5 RC4   Edit
Assignee: Sergey Prigogin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-29 14:57 EDT by Sergey Prigogin CLA
Modified: 2015-06-03 19:44 EDT (History)
4 users (show)

See Also:
jarthana: review+
markus.kell.r: review+
daniel_megert: review+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2015-05-29 14:57:54 EDT
This exception happens in 4.5RC2 but not in 4.4.2.

java.lang.NullPointerException
        at org.eclipse.jdt.internal.compiler.Compiler.restoreAptProblems(Compiler.java:514)
        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:457)
        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:452)
        at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:367)
        at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:179)
        at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:304)
        at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:61)
        at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:256)
        at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:175)
        at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:329)
        at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:404)
        at org.eclipse.core.internal.resources.Project$1.run(Project.java:556)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
        at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:534)
        at org.eclipse.core.internal.resources.Project.build(Project.java:119)

Unfortunately, I don't have a self-contained example that triggers this problem.
Comment 1 Eclipse Genie CLA 2015-05-29 18:09:30 EDT
New Gerrit change created: https://git.eclipse.org/r/49014
Comment 2 Walter Harley CLA 2015-05-30 01:23:12 EDT
I'm having a hard time understanding the Gerrit review format.  Is the "for (CompilationUnitDeclaration unitDecl : this.unitsToProcess)" version the new one, or the old one?

If it's the new one, it looks good.  If it's the old one, I don't understand the change.
Comment 3 Sergey Prigogin CLA 2015-05-30 19:52:53 EDT
(In reply to Walter Harley from comment #2)
> I'm having a hard time understanding the Gerrit review format.  Is the "for
> (CompilationUnitDeclaration unitDecl : this.unitsToProcess)" version the new
> one, or the old one?
> 
> If it's the new one, it looks good.  If it's the old one, I don't understand
> the change.

The modified code is on the right. The unitsToProcess array contains valid data only in the first totalUnits elements.
Comment 4 Walter Harley CLA 2015-05-30 20:59:51 EDT
I see.

The reason this code has had so many bugs over its history is because it violates separation of concerns and it violates principle of least surprise.  This bug is an example of that: the management of the array (the logical coupling of unitsToProcess and totalUnits, and the array-growing algorithm) is mixed up with the use of the array.  Presented with an array it's reasonable to think that it's safe to iterate over the whole array, but in this case it's not.  So you end up reintroducing iteration with i++, which opens the door to off by one errors and the like.

This code would be a lot cleaner if the array data structure was a separate class.  And at this point I really wonder whether managing our own array growing and shrinking is buying us any performance.  Grumble.

Anyway, I guess in terms of actual bugs, the change seems correct as far as I can tell.
Comment 5 Jay Arthanareeswaran CLA 2015-06-01 00:26:21 EDT
Sorry I was away on leave during the last week. It would be good to know the scenario causing this so we can evaluate including this for Mars, although we are already in RC4.
Comment 6 Dani Megert CLA 2015-06-01 03:55:27 EDT
(In reply to Jay Arthanareeswaran from comment #5)
> Sorry I was away on leave during the last week. It would be good to know the
> scenario causing this so we can evaluate including this for Mars, although
> we are already in RC4.

Or a test case.

The proposed code change itself looks good to me.
Comment 7 Sergey Prigogin CLA 2015-06-01 11:33:55 EDT
(In reply to Jay Arthanareeswaran from comment #5)
> Sorry I was away on leave during the last week. It would be good to know the
> scenario causing this so we can evaluate including this for Mars, although
> we are already in RC4.

Unfortunately, I don't have a self contained reproduction case. Still it is a no-brainer that the change should be included in Mars. It's pretty obvious that the code before the change is incorrect and requires modification.
Comment 8 Jay Arthanareeswaran CLA 2015-06-01 12:42:53 EDT
(In reply to Sergey Prigogin from comment #7)
> Still it is
> a no-brainer that the change should be included in Mars. It's pretty obvious
> that the code before the change is incorrect and requires modification.

No doubt, it just that it makes it easier to get approvals when we have a reproducible test case. I agree with the proposed changes.
Comment 9 Markus Keller CLA 2015-06-01 14:39:56 EDT
+1 for RC4. The code change looks safe, and I've added a test case to the review. Without the fix, the test fails with the given NPE.

Filed bug 469031 for a SourceTypeCollisionException that escapes from the compiler when I modify the test a bit.
Comment 10 Dani Megert CLA 2015-06-01 15:04:48 EDT
(In reply to Dani Megert from comment #6)
> (In reply to Jay Arthanareeswaran from comment #5)
> > Sorry I was away on leave during the last week. It would be good to know the
> > scenario causing this so we can evaluate including this for Mars, although
> > we are already in RC4.
> 
> Or a test case.
> 
> The proposed code change itself looks good to me.

+1.
Comment 12 Markus Keller CLA 2015-06-01 15:10:31 EDT
Submitted.
Comment 13 Jay Arthanareeswaran CLA 2015-06-02 08:05:06 EDT
Verified for 4.5 RC4 with build I20150601-2000.

Sergey, I encourage you to grab this build and confirm it works in your environment too.
Comment 14 Sergey Prigogin CLA 2015-06-03 19:44:47 EDT
(In reply to Jay Arthanareeswaran from comment #13)
Confirmed.