Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 162595 - ClassCastException: com.sun.tools.javac.tree.JCTree$JCArrayTypeTree cannot be cast to com.sun.source.tree.IdentifierTree
ClassCastException: com.sun.tools.javac.tree.JCTree$JCArrayTypeTree cannot be...
Status: VERIFIED FIXED
Product: projects
Classification: Unclassified
Component: Maven
6.x
All All
: P3 (vote)
: 6.x
Assigned To: Milos Kleint
issues@platform
http://statistics.netbeans.org/except...
EXCEPTIONS_REPORT 67patch1-verified
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-04-14 14:46 UTC by jonathanramsey
Modified: 2009-07-20 14:39 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
stacktrace (1.13 KB, text/plain)
2009-04-14 14:47 UTC, jonathanramsey
Details
stacktrace (1.21 KB, text/plain)
2009-04-15 18:26 UTC, hohonuuli
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jonathanramsey 2009-04-14 14:46:56 UTC
Build: NetBeans IDE 6.5 (Build 200811100001)
VM: Java HotSpot(TM) Client VM, 10.0-b22, Java(TM) SE Runtime Environment, 1.6.0_06-b02
OS: Windows XP, 5.1, x86

User Comments:
jonathanramsey: The exception triggered on one of two changes I made to this code:

private Object[][] data1 = new Object[][] {
    { new Round("DO", "XYZ"), "XYZ" },
    { new Round("RE", "ABC"), "ABC" },
    { new Round("OR", "123"), "123" },
};

First change: I inserted a 3 into the first set of square brackets.

private Object[3][] data1 = new Object[][] {
    { new Round("DO", "XYZ"), "XYZ" },
    { new Round("RE", "ABC"), "ABC" },
    { new Round("OR", "123"), "123" },
};

Second change: I inserted a 2 into the second set of square brackets.

private Object[3][2] data1 = new Object[][] {
    { new Round("DO", "XYZ"), "XYZ" },
    { new Round("RE", "ABC"), "ABC" },
    { new Round("OR", "123"), "123" },
};

I did both of these changes absent mindedly. I should have put the array sizes into the second set of square brackets e.g.  private Object[][] data1 = new Object[3][2] {. I'm fairly sure it isn't valid Java syntax to put sizes into the first set of square brackets. I think the editor should ju

jonathanramsey: I typed Collection< in front of Object[], and got this exception.

jblume: right after typing "HashMap<" in a Java file

tnleeuw: 1. I invoked code-completion on an incomplete identifier
2. I cancellded the code-completion
3. I invoked the 'emacs-like' alt-/ word expansion (forgot the name of the command, sorry, that's why I have to describe it like that)

The identifier was expanded to the desired result but immediately afterwards this exception was raised.



Stacktrace: 
java.lang.ClassCastException: com.sun.tools.javac.tree.JCTree$JCArrayTypeTree cannot be cast to com.sun.source.tree.IdentifierTree
        at org.netbeans.modules.maven.hints.errors.SearchClassDependencyInRepo.run(SearchClassDependencyInRepo.java:238)
        at org.netbeans.modules.java.hints.infrastructure.CreatorBasedLazyFixList.compute(CreatorBasedLazyFixList.java:144)
        at org.netbeans.modules.java.hints.infrastructure.LazyHintComputation.run(LazyHintComputation.java:109)
        at org.netbeans.modules.java.hints.infrastructure.LazyHintComputation.run(LazyHintComputation.java:55)
        at org.netbeans.api.java.source.JavaSource$CompilationJob.run(JavaSource.java:1729)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
Comment 1 jonathanramsey 2009-04-14 14:47:02 UTC
Created attachment 80043 [details]
stacktrace
Comment 2 hohonuuli 2009-04-15 18:26:37 UTC
Build: NetBeans IDE Dev (Build 200904011705)
VM: Java HotSpot(TM) Client VM, 1.5.0_16-133, Java(TM) 2 Runtime Environment, Standard Edition, 1.5.0_16-b06-284
OS: Mac OS X, 10.5.6, i386

User Comments: 


Stacktrace: 
java.lang.ClassCastException: com.sun.tools.javac.tree.JCTree$JCPrimitiveTypeTree
        at org.netbeans.modules.maven.hints.errors.SearchClassDependencyInRepo.run(SearchClassDependencyInRepo.java:238)
        at org.netbeans.modules.java.hints.infrastructure.CreatorBasedLazyFixList.compute(CreatorBasedLazyFixList.java:144)
        at org.netbeans.modules.java.hints.infrastructure.LazyHintComputation.run(LazyHintComputation.java:109)
        at org.netbeans.modules.java.hints.infrastructure.LazyHintComputation.run(LazyHintComputation.java:55)
        at org.netbeans.modules.java.source.JavaSourceAccessor$CancelableTaskWrapper.run(JavaSourceAccessor.java:288)
        at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:681)
Comment 3 hohonuuli 2009-04-15 18:26:47 UTC
Created attachment 80180 [details]
stacktrace
Comment 4 Milos Kleint 2009-04-17 09:55:22 UTC
dbalek: any hints? the code looks like this:

                            case NEW_ARRAY:
                                 {
                                    NewArrayTree arrayTree = (NewArrayTree) initializer;
                                    Tree type = arrayTree.getType();
                                    if (type != null) {
                                        itName = ((IdentifierTree) type).getName();
                                    }
                                }
                                break;

the exception comes from the IdentifierTree cast..
Comment 5 Milos Kleint 2009-06-05 11:01:57 UTC
reassigning to java for evaluation, please advice how to improve the code mentioned above
Comment 6 Jan Lahoda 2009-06-05 11:11:53 UTC
What is wrong in Java?

Consider:
-new Object[0] - is a new array, whose type is IdentifierTree "Object"
-new Object[0][] - is a new array, whose type is ArrayTypeTree "Object[]"
-int[0] - is a new array, whose type is PrimiteTypeTree "int"

Not sure that code is supposed to do, but it should check whether the type is an identifier (through getKind ideally)
before casting to an IdentifierTree, and possibly handle the other cases too.
Comment 7 Milos Kleint 2009-06-26 12:54:04 UTC
http://hg.netbeans.org/main/rev/8d60f647ad73
Comment 8 Quality Engineering 2009-06-27 05:39:04 UTC
Integrated into 'main-golden', will be available in build *200906270201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/8d60f647ad73
User: Milos Kleint <mkleint@netbeans.org>
Log: #162595 prevent casting error
Comment 9 Jaroslav Pospisil 2009-07-02 13:09:28 UTC
v.
Comment 10 pgebauer 2009-07-09 22:39:38 UTC
The fix has been ported into the release67_fixes repository.
http://hg.netbeans.org/release67_fixes/rev/e970030d5df5


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo