Bug 233625

Summary: Content Assist outof memory
Product: [Eclipse Project] JDT Reporter: Xiang Qinxian <fyaoxy>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: david_audel, martinae, philippe_mulet
Version: 3.4Flags: philippe_mulet: review+
frederic_fusier: review+
david_audel: review+
Target Milestone: 3.4 RC3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix and regression test
none
New proposed fix and new regression tests
none
Same patch with more null checks none

Description Xiang Qinxian CLA 2008-05-23 04:13:27 EDT
Build ID: I20080516-1333

Steps To Reproduce:
1.input this line:
private Map<Class<?>,List<Field>> map = new Hashmap
2.where Map List already imported
import java.util.List;
import java.util.Map;
3.now Alt+/ jdt report outofMemory


More information:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:390)
at java.lang.StringBuilder.append(StringBuilder.java:119)
at java.lang.StackTraceElement.toString(StackTraceElement.java:157)
at java.lang.String.valueOf(String.java:2827)
at java.lang.StringBuilder.append(StringBuilder.java:115)
at java.lang.Throwable.printStackTrace(Throwable.java:464)
at java.lang.Throwable.printStackTrace(Throwable.java:451)
at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:593)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.handleInternalException(CompilationUnitResolver.java:317)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:767)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:474)
at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:736)
at org.eclipse.jdt.internal.ui.text.java.LazyGenericTypeProposal.getExpectedType(LazyGenericTypeProposal.java:603)
at org.eclipse.jdt.internal.ui.text.java.LazyGenericTypeProposal.computeTypeArgumentProposals(LazyGenericTypeProposal.java:298)
at org.eclipse.jdt.internal.ui.text.java.LazyGenericTypeProposal.apply(LazyGenericTypeProposal.java:195)
at org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal.apply(AbstractJavaCompletionProposal.java:443)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:923)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$21(CompletionProposalPopup.java:887)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:492)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:479)
at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions(ContentAssistant.java:1662)
at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:177)
at org.eclipse.ui.texteditor.ContentAssistAction$1.run(ContentAssistAction.java:82)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at org.eclipse.ui.texteditor.ContentAssistAction.run(ContentAssistAction.java:80)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
Comment 1 Jerome Lanneluc CLA 2008-05-23 09:34:32 EDT
The problem is an infinite loop in the BindingKeyResolver for the following binding key: "Ljava/util/Map<Ljava/lang/Class<Ljava/lang/Class;*>;Ljava/util/List<LField;>;>;", With this case, the first loop in BindingKeyParser.parseParameterizedType(char[], boolean) never ends.

This bug was introduced in 3.3 by the fix to bug 111529. The fact that an IllegalArgumentException is thrown and then caught fails to have the scanner progress for parameterized type. As a result, the isAtParametersEnd() condition is never true.

This code was not used by code assist in 3.3, so this bug cannot be reproduced in 3.3. This makes it a regression from a user point of view comparing to 3.3.

We should fix it for RC3.
Comment 2 Jerome Lanneluc CLA 2008-05-23 09:39:54 EDT
Created attachment 101731 [details]
Proposed fix and regression test
Comment 3 Philipe Mulet CLA 2008-05-23 10:29:58 EDT
Given it no longer escapes with the proposed patch, does it exit properly from such a bogus scenario ?

List<Zork>.Map<Object,Number>

i.e. it should not ignore the (bogus) leading part.
Comment 4 Jerome Lanneluc CLA 2008-05-23 12:32:55 EDT
(In reply to comment #3)
> Given it no longer escapes with the proposed patch, does it exit properly from
> such a bogus scenario ?
> 
> List<Zork>.Map<Object,Number>
> 
> i.e. it should not ignore the (bogus) leading part.
> 
In this scenario, an NPE would be logged to the .log file and null would be returned.
Comment 5 Jerome Lanneluc CLA 2008-05-23 12:40:16 EDT
Created attachment 101771 [details]
New proposed fix and new regression tests

This patch fixes the issue noticed by Philippe, and it adds more tests.
Comment 6 Jerome Lanneluc CLA 2008-05-23 12:42:49 EDT
Philippe, Frederic and David, could you please review?
Comment 7 Frederic Fusier CLA 2008-05-26 04:55:43 EDT
Patch looks good: +1
Comment 8 David Audel CLA 2008-05-26 05:22:02 EDT
Patch looks good: +1
Comment 9 Jerome Lanneluc CLA 2008-05-27 06:35:46 EDT
Created attachment 102124 [details]
Same patch with more null checks
Comment 10 Philipe Mulet CLA 2008-05-27 10:15:04 EDT
+1 for 3.4RC3

Minor comment (perf):
this.types = new ArrayList(); --> this.types.clear();

Going into performance, as per discussion with Jerome, there may be other enhancements to make so as to avoid allocating multiple resolvers etc... but this is a separate issue.

Comment 11 Jerome Lanneluc CLA 2008-05-27 11:37:46 EDT
Fix and tests released for 3.4RC3
Comment 12 David Audel CLA 2008-05-30 10:55:22 EDT
Verified for 3.4RC4 using build I20080530-0100