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

Bug 288060

Summary: [quick fix]: Ctrl-2 + L to trigger quick fix causes NPE if the method returns an array (Mobile projects only)
Product: [Eclipse Project] JDT Reporter: Christian <chriszi>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, wds057, whm012
Version: 3.5   
Target Milestone: 3.6 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
The stacktrace taken from the eclipse .log file none

Description Christian CLA 2009-08-30 16:05:35 EDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)
Build Identifier: Pulsar for Mobile Java Developers. Build id: 20090619-0625

The Quick-Fix obtained by Ctrl-1 or Ctrl-2, L (and as well for class fields) foes not work if the resulting field/variable would be an array type. This is caused by a NPE for which the stacktrace is attached.

Reproducible: Always

Steps to Reproduce:
1. Create a new empty MTJ project
2. Add a class with the following methods:
public class TestClass {
    public int[] test() {
        return null;
    }

    public void test2() {
        this.test();
    }
}
3. Set the cursor to "this.test();" and press Ctrl-2 and then L
4. Nothing happens, but a stacktrace will appear in the .log file of the workspace. However this shortcut works fine for the same class if contained in a normal JavaSE project.



I did retest this with the 3.5. RC1 build of eclipse and the bug is still there.
Comment 1 Christian CLA 2009-08-30 16:07:12 EDT
Created attachment 146013 [details]
The stacktrace taken from the eclipse .log file

The error will always occur at the position noted by the stacktrace, however the stacktrace may vary ecept for the few topmost lines.
Comment 2 Henrique Magalhães CLA 2009-09-03 08:27:21 EDT
The problem occurs when the JDT (org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getRelaxingTypes(AST, ITypeBinding)) tries to create an instance of "java.io.Serializable" and "java.lang.Cloneable" classes.
Both classes are not present on MTJ project classpath and return a null value.
Comment 3 Henrique Magalhães CLA 2009-09-03 09:53:58 EDT
This is an internal implementation for JDT,
and has no extension point or OSGi services that can be used for the correction on MTJ side.

(In reply to comment #2)
> The problem occurs when the JDT
> (org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getRelaxingTypes(AST,
> ITypeBinding)) tries to create an instance of "java.io.Serializable" and
> "java.lang.Cloneable" classes.
> Both classes are not present on MTJ project classpath and return a null value.
Comment 4 Diego Madruga Sandin CLA 2009-09-03 09:56:26 EDT
Cant be fixed.
Comment 5 Christian CLA 2009-09-03 12:59:09 EDT
Well sorry to say that but I guess you are making it a little bit too easy for yourselves - if this bug really can't be fixed on your side, it should be fixable by the JDT team. Then however I'm wondering why this error only occurs in MTJ projects. 
Therefore I reopen this bug and hope that it can be reassigned to another team which can fix it or if you decide that this bug is just too minor to be fixed, it should be stated that way.
Comment 6 Christian CLA 2009-09-09 02:28:15 EDT
I changed the Product/Component of the bug to JDT/Pulsar, can you please reassign it to the appropriate person/list in that Project?
Comment 7 Christian CLA 2009-09-13 16:02:51 EDT
Just wanted to add that this error occurs not only for the described Quick-Fix but also for at least the "Add Parameter to Method" Quick-Fix as well.
Comment 8 Markus Keller CLA 2009-09-15 05:35:36 EDT
(In reply to comment #2)
> The problem occurs when the JDT
> (org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getRelaxingTypes(AST,
> ITypeBinding)) tries to create an instance of "java.io.Serializable" and
> "java.lang.Cloneable" classes.
> Both classes are not present on MTJ project classpath and return a null value.

That should be easy to fix for us. Should also check other usages of AST#resolveWellKnownType(String).

Henrique, where can I find information about available types in the JRE that is used for MTJ projects? Are all the other types listed in AST#resolveWellKnownType(String) available?
Comment 9 Markus Keller CLA 2009-09-15 05:37:18 EDT
*** Bug 289315 has been marked as a duplicate of this bug. ***
Comment 10 Christian CLA 2009-09-17 03:04:49 EDT
@Markus Keller: Unfortunately the classes in the classpath of a j2me app depend a bit on the cldc used (the java version). 
As of cldc 1.1 (imo the most common by now)
the following classes mentioned in DefaultBindingResolver #resolveWellKnownType
are not part of cldc 1.1 (as mentioned already by Henrique): 
- java.lang.Cloneable
- java.io.Serializable

The list of classes available in cldc 1.0 can be found here: http://java.sun.com/javame/reference/apis/jsr030/ however I don't think that they still matter so much.
Comment 11 Markus Keller CLA 2009-10-14 13:57:42 EDT
Fixed in HEAD. Checked other usages of AST#resolveWellKnownType(String), found no problematic cases.
Comment 12 Christian CLA 2009-11-07 10:21:53 EST
Just downloaded the M3 version of eclipse Helios and can verify - it's fixed.