Bug 177115 - NullPointerException in BindingKeyResolver.consumeTypeVariable(...)
Summary: NullPointerException in BindingKeyResolver.consumeTypeVariable(...)
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 86990 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-03-13 05:14 EDT by Philipe Mulet CLA
Modified: 2008-09-16 09:42 EDT (History)
2 users (show)

See Also:


Attachments
Corresponding reverse patch (5.06 KB, patch)
2007-03-14 07:21 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2007-03-13 05:14:49 EDT
Build id: I20070228-0930

Trying to complete in code below where RED, I selected 'DataChangeList<T>'
and nothing got inserted, but a NPE got dumped into the console.
------------------------------

import java.util.ArrayList;
import java.util.List;

class ArchiveRecordList<R extends ArchiveRecord> extends ArrayList<R> {
      @Override public ArchiveRecordList<R> subList(int fromIndex, int
toIndex) {
            return (ArchiveRecordList<R>)super.subList(fromIndex, toIndex);
      }
}

class DataChangeList<T> extends ArchiveRecordList<DataChangeRecord<T>> {
      public DataChangeList<T> getDataBetween(long from, long to) {
            return (Data[ASSIST-HERE]subList(indexOf(from), indexOf(to) +
1);
      }
}

class IntDataChangeList extends DataChangeList<Integer> {
      public IntDataChangeList getDataBetween(long from, long to) {
            return super.getDataBetween(from, to);
      }
}

class DblDataChangeList extends DataChangeList<Double> {
      public DblDataChangeList getDataBetween(long from, long to) {
            return super.getDataBetween(from, to);
      }
}

class ArchiveRecord {}
class DataChangeRecord<T> extends ArchiveRecord {}



=========================

!ENTRY org.eclipse.ui 4 0 2007-03-13 10:11:41.858
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
        at org.eclipse.jdt.internal.core.util.BindingKeyResolver.consumeTypeVariable(BindingKeyResolver.java:348)
        at org.eclipse.jdt.internal.core.util.BindingKeyParser.parseTypeVariable(BindingKeyParser.java:823)
        at org.eclipse.jdt.internal.core.util.BindingKeyParser.parse(BindingKeyParser.java:591)
        at org.eclipse.jdt.internal.core.util.BindingKeyParser.parse(BindingKeyParser.java:529)
        at org.eclipse.jdt.internal.core.util.BindingKeyParser.parseTypeArgument(BindingKeyParser.java:796)
        at org.eclipse.jdt.internal.core.util.BindingKeyParser.parseParameterizedType(BindingKeyParser.java:752)
        at org.eclipse.jdt.internal.core.util.BindingKeyParser.parse(BindingKeyParser.java:561)
        at org.eclipse.jdt.internal.core.util.BindingKeyParser.parse(BindingKeyParser.java:529)
        at org.eclipse.jdt.internal.core.util.BindingKeyResolver.getCompilerBinding(BindingKeyResolver.java:446)
        at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:790)
        at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:466)
        at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:705)
        at org.eclipse.jdt.internal.ui.text.java.LazzyGenericTypeProposal.getExpectedType(LazzyGenericTypeProposal.java:602)
        at org.eclipse.jdt.internal.ui.text.java.LazzyGenericTypeProposal.computeTypeArgumentProposals(LazzyGenericTypeProposal.java:298)
        at org.eclipse.jdt.internal.ui.text.java.LazzyGenericTypeProposal.apply(LazzyGenericTypeProposal.java:195)
        at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.apply(AbstractJavaCompletionProposal.java:453)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:806)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:757)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1164)
        at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:782)
        at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:438)
        at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:61)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
        at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:706)
        at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5075)
        at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:4817)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:962)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:947)
        at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:975)
        at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:971)
        at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1285)
        at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3601)
        at org.eclipse.swt.widgets.Control.windowProc(Control.java:3501)
        at org.eclipse.swt.widgets.Display.windowProc(Display.java:4308)
        at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
        at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2209)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3251)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2306)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2270)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2145)
        at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:460)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:455)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:101)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:146)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:169)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:476)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:416)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1124)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1099)
Comment 1 Philipe Mulet CLA 2007-03-13 07:45:10 EDT
Reproduced in debugger: offending signature looks like:
LX~DataChangeList<LX~DataChangeList;:TT;>;
Comment 2 Philipe Mulet CLA 2007-03-13 07:47:24 EDT
Issue is located on line marked with '>>>>>>>' since both methodBinding and typeBinding are null.

	public void consumeTypeVariable(char[] position, char[] typeVariableName) {
		if (position.length > 0) {
			int pos = Integer.parseInt(new String(position));
			MethodBinding[] methods = ((ReferenceBinding) this.typeBinding).methods();
			if (methods != null && pos < methods.length) {
				this.methodBinding = methods[pos];
			}
		}
>>>>>>>	 	TypeVariableBinding[] typeVariableBindings = this.methodBinding != null ? this.methodBinding.typeVariables() : this.typeBinding.typeVariables();
	 	for (int i = 0, length = typeVariableBindings.length; i < length; i++) {
			TypeVariableBinding typeVariableBinding = typeVariableBindings[i];
			if (CharOperation.equals(typeVariableName, typeVariableBinding.sourceName())) {
				this.typeBinding = typeVariableBinding;
				return;
			}
		}
	}
Comment 3 Philipe Mulet CLA 2007-03-13 08:12:36 EDT
Missing step: the unit file name was "X.java".
Looks like the decoding doesn't handle situation where no 'X' type is actually present in the unit.

Feels like the support for finding secondary types could be used directly, instead of relying on ability to find a primary type.
Comment 4 Jerome Lanneluc CLA 2007-03-13 10:29:35 EDT
To reproduce:
1. Start a new workspace on a 1.5 VM
2. Create a new Java project (verify that compliance is 1.5)
3. Create a new type X in the default package
4. In the X.java editor, replace the whole content with:
class Y<T> {
	public Y<T> foo() {
		return Y//complete here
	}
}

5. Code complete after 2nd Y
Observe: you get the NPE reported above in the .log
Comment 5 Jerome Lanneluc CLA 2007-03-14 05:33:25 EDT
Changed BindingKeyParser to parse the secondary type name before pausing after fully qualified name parsing.
Changed BindingKeyResolver to handle null binding when looking up the primary type binding, and to default to use the secondary type lookup.
Added regression test BatchASTCreationTests#test083().

Released for 3.3M6 in HEAD.
Comment 6 Jerome Lanneluc CLA 2007-03-14 06:15:43 EDT
*** Bug 86990 has been marked as a duplicate of this bug. ***
Comment 7 Philipe Mulet CLA 2007-03-14 07:03:44 EDT
Pls backport to 3.2.x stream.
Comment 8 Jerome Lanneluc CLA 2007-03-14 07:21:41 EDT
Created attachment 60778 [details]
Corresponding reverse patch

To apply, choose the Reverse patch option in the Apply patch wizard.
Comment 9 Jerome Lanneluc CLA 2007-03-14 09:01:30 EDT
Patch applied in R3_2_maintenance stream (no target milestone yet)
Comment 10 Maxime Daniel CLA 2007-03-20 04:15:19 EDT
Verified for 3.3 M6 using build I20070319-1335.
Comment 11 Frederic Fusier CLA 2008-09-16 09:42:27 EDT
> Verified for 3.3 M6 using build I20070319-1335.
>