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

Bug 324154

Summary: NPE in FlowContext while building
Product: [Eclipse Project] JDT Reporter: Benjamin Muskalla <b.muskalla>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: amj87.iitr, daniel_megert, jarthana, Olivier_Thomann, srikanth_sankaran
Version: 3.7Flags: daniel_megert: pmc_approved+
amj87.iitr: review+
Olivier_Thomann: review+
Target Milestone: 3.6.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
project
none
Simplified test case
none
Untested patch
none
Cleaner patch + junit - under test
none
Much simpler patch - under test none

Description Benjamin Muskalla CLA 2010-08-31 21:31:04 EDT
Just synchronized my workspace when this happend. Besides the error in the log, there is a compile error in org.eclipse.rap.examples.pages.Elements in line 0 telling me the same.

-- Error Details --
Date: Wed Sep 01 03:26:24 CEST 2010
Message: Errors running builder 'Java Builder' on project 'org.eclipse.rap.examples.pages'.
Severity: Error
Product: Eclipse SDK 3.7.0.v201008262000 (org.eclipse.sdk.ide)
Plugin: org.eclipse.jdt.core
Session Data:
eclipse.buildId=N20100826-2000
java.version=1.6.0_20
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US
Framework arguments:  -server -showLocation
Command-line arguments:  -os linux -ws gtk -arch x86 -server -showLocation


Exception Stack Trace:
java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.flow.FlowContext.checkExceptionHandlers(FlowContext.java:152)
at org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext.checkInitializerExceptions(InitializationFlowContext.java:46)
at org.eclipse.jdt.internal.compiler.ast.Clinit.analyseCode(Clinit.java:81)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:687)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:253)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:111)
at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:765)
at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:137)
at java.lang.Thread.run(Thread.java:619)
Comment 1 Benjamin Muskalla CLA 2010-08-31 21:31:42 EDT
Created attachment 177903 [details]
project

Attached the project in question
Comment 2 Olivier Thomann CLA 2010-08-31 22:03:07 EDT
This is a consequence of the fix for bug 321926.
Ayushman, please follow up.
Comment 3 Olivier Thomann CLA 2010-08-31 22:07:14 EDT
Created attachment 177905 [details]
Simplified test case
Comment 4 Srikanth Sankaran CLA 2010-08-31 23:16:29 EDT
Created attachment 177909 [details]
Untested patch

Some parameters that are irrelevant to  org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext.recordHandlingException(ReferenceBinding, UnconditionalFlowInfo, TypeBinding, ASTNode, boolean)

are relevant to 

org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext.recordHandlingException(ReferenceBinding, UnconditionalFlowInfo, TypeBinding, ASTNode, boolean)

It is really the former call that we care about, but it was an oversight to
not have recognized that calls can dispatch to the latter.

It also errorneous to call the latter in the loop back context as this
can double report problems with unhandled exceptions.

Ayush, this patch is not tested and can be cleaner perhaps. Please take
a look.
Comment 5 Srikanth Sankaran CLA 2010-09-01 05:59:18 EDT
Smaller test case: 

import java.io.*;
public class X {
  static {
    try {
      while(true) {
    	  if (true)
    		  throw new NumberFormatException();
    	  else
    		  throw new IOException();
      }
    } catch(IOException e ) {
    	// empty
    } 
  } 
}
Comment 6 Srikanth Sankaran CLA 2010-09-01 06:53:45 EDT
Created attachment 177930 [details]
Cleaner patch + junit - under test
Comment 7 Srikanth Sankaran CLA 2010-09-01 06:57:33 EDT
As an aside, it looks a bit odd that InitializationFlowContext extends
ExceptionHandlingFlowContext - I am not sure there isn't an abstraction
problem here -- Ignoring this issue for now.
Comment 8 Srikanth Sankaran CLA 2010-09-01 09:06:26 EDT
All tests pass, Ayush, please review. TIA.
Comment 9 Srikanth Sankaran CLA 2010-09-01 10:08:20 EDT
Created attachment 177955 [details]
Much simpler patch - under test

A much simpler patch per Ayush's suggestion.
We discussed the earlier patch and while it
concluded it would work properly, we also felt
it is needlessly complicated.

Since all we want to do is to update the entry
flow information for catch blocks to reflect
the flow data at the end of the loop, we need
to record only those exceptions that have a
catch block - this simply eliminates the calls
to org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext.recordHandlingException(ReferenceBinding, UnconditionalFlowInfo, TypeBinding, ASTNode, boolean)
from ever happening again eliminating the possibility of the
NPE.
Comment 10 Srikanth Sankaran CLA 2010-09-01 11:37:31 EDT
(In reply to comment #9)
> Created an attachment (id=177955) [details]
> Much simpler patch - under test

All tests pass. Ayush please take a look.
Comment 11 Ayushman Jain CLA 2010-09-01 11:42:43 EDT
Looks good.
Comment 12 Srikanth Sankaran CLA 2010-09-01 11:52:43 EDT
Released in HEAD for 3.7 M2.

Olivier, the patch is extremely simple, if we have a chance, we should
deliver this for 3.6.1, do you agree ?
Comment 13 Olivier Thomann CLA 2010-09-01 12:25:31 EDT
(In reply to comment #12)
> Released in HEAD for 3.7 M2.
> Olivier, the patch is extremely simple, if we have a chance, we should
> deliver this for 3.6.1, do you agree ?
We have no choice as this is a regression over 3.6. The fix for 321926 created this problem and since this fix is in 3.6.1 we also must release this one to get back to normal.
Daniel, we need PMC approval.

This is the NPE I was referring to at the arch call this morning.
Comment 14 Dani Megert CLA 2010-09-01 12:35:44 EDT
>We have no choice as this is a regression over 3.6.
I agree, this is a must fix. +1 for 3.6.1 RC3.
Comment 15 Olivier Thomann CLA 2010-09-01 12:44:47 EDT
Reopen to close as RESOLVED for 3.6.1.
Comment 16 Olivier Thomann CLA 2010-09-01 13:01:57 EDT
Released for 3.6.1.
Same patch.
Comment 17 Jay Arthanareeswaran CLA 2010-09-02 01:14:11 EDT
Verified for 3.6.1 using build M20100901-1310.
Comment 18 Benjamin Muskalla CLA 2010-09-02 09:40:31 EDT
Thanks guys!
Comment 19 Olivier Thomann CLA 2010-09-14 10:52:01 EDT
Verified for 3.7M2 using I20100914-0100