This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 135153 - ClassCastException: org.mozilla.javascript.Node cannot be cast to org.mozilla.javascript.Node$StringNode
Summary: ClassCastException: org.mozilla.javascript.Node cannot be cast to org.mozilla...
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Marek Fukala
URL: http://statistics.netbeans.org/except...
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-15 14:57 UTC by Martin Schovanek
Modified: 2009-02-27 14:26 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 52125


Attachments
ide log (129.17 KB, text/plain)
2008-05-16 08:34 UTC, unr303
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Schovanek 2008-05-15 14:57:24 UTC
to reproduce:
-------------
Just opening the dojo.js


Build: NetBeans IDE Dev (Build 200805060003)
VM: Java HotSpot(TM) Client VM, 10.0-b19, Java(TM) SE Runtime Environment, 1.6.0_05-b13
OS: Windows XP, 5.1, x86
User comments: Opening a file contains javascript (prototype, scriptaculous) 
STACKTRACE: (first 10 lines)
java.lang.ClassCastException: org.mozilla.javascript.Node cannot be cast to org.mozilla.javascript.Node$StringNode
        at org.mozilla.javascript.Node.getString(Node.java:685)
        at org.netbeans.modules.javascript.editing.JsSemanticAnalyzer.run(JsSemanticAnalyzer.java:137)
        at org.netbeans.modules.javascript.editing.JsSemanticAnalyzer.run(JsSemanticAnalyzer.java:65)
        at org.netbeans.modules.gsfret.editor.semantic.SemanticHighlighter.process(SemanticHighlighter.java:140)
        at org.netbeans.modules.gsfret.editor.semantic.SemanticHighlighter.run(SemanticHighlighter.java:110)
        at org.netbeans.modules.gsfret.editor.semantic.SemanticHighlighter.run(SemanticHighlighter.java:76)
        at org.netbeans.napi.gsfret.source.Source$CompilationJob.run(Source.java:1278)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
Comment 1 Torbjorn Norbye 2008-05-15 21:31:39 UTC
This is probably a regression caused by 
http://hg.netbeans.org/main/rev/27dc0e1e31ee

and specifically, these three lines:

+ if(JsModel.isGeneratedIdentifier(node.getString())) {
+ continue;
+ } 

Marek, in this case, node will be Token.REGEXP, Token.FUNCNAME, or Token.OBJLITNAME, and a regexp cannot be cast to a
StringNode (which is what node.getString does.  Yes, the Rhino AST is a bit weird - it defines a getString method which
throws an exception if the method is called on a node type which doesn't support it).

I'm bumping the priority on this since it shows up when you open pretty much any large file (any file containing a regexp).

(I can fix this on Friday if you don't get to it sooner - I'm on my way out the door. There's a unit test for
JsSemanticAnalyzer so you should be able to use it to verify the bug.)
Comment 2 Exceptions Reporter 2008-05-16 08:32:39 UTC
This issue has already 5 duplicates 
Comment 3 unr303 2008-05-16 08:33:41 UTC
Edited
/**
 * Helps to compose blocks of text.
 */
function TextBlock(){
    this.text="";
    /**
     * Adds text as new line.
     */
    this.addLine=function(text){
        this.text+=text+"\n";
    }
    /**
     * Adds block of text.
     */
    this.addText=function(text){
        this.text+=text;
    }
    /**
     * Returns accumulated text.
     */
    this.getText=function(){
        return this.text;
    }
}

function Template(template){
    this.template=template;
    this.params=new Array();
    this.setParameter=function(name,value){
        this.params[name]=new Array();
        this.params[name]["name"]=name;
        this.params[name]["value"]=value;
    }
    this.eval=function(){
        result=this.template;
        for(param in this.params){
            result.replace(/this.params[param]["name"]/g,this.params[param]["value"]);
                
                this.params[param]["name"]+" -> "+this.params[param]["value"]+"\n";
        }
        return result;
    }
}

/**
 * Represents Java source file.
 */
function JavaSource(){
    this.packageName="";
    this.imports=new Array();
    this.declaration="";
    this.body="";
    this.addImport=function(importName){
        this.imports.push(importName);
    }
    this.getImports=function(){
        result = new TextBlock();
        for(importName in this.imports){
            result.addLine("import "+this.imports[importName]+";");
        }
        return result.getText();
    }
}
source= new JavaSource();
source.addImport("org.a");
source.addImport("org.b");
source.getImports();
Comment 4 unr303 2008-05-16 08:34:12 UTC
Created attachment 61466 [details]
ide log
Comment 5 Marek Fukala 2008-05-16 11:11:52 UTC
fixed in revision a000a5ddcd39

- if(JsModel.isGeneratedIdentifier(node.getString())) {
+ if(node.isStringNode() && JsModel.isGeneratedIdentifier(node.getString())) {

though I didn't check the node's instance by type (int) creation so it may never be true even for Token.FUNCNAME, or
Token.OBJLITNAME. Please correct if necessary.

I am sorry for the regression.
Comment 6 Quality Engineering 2008-05-20 05:18:12 UTC
Integrated into 'main-golden', available in NB_Trunk_Production #206 build
Changeset: http://hg.netbeans.org/main/rev/a000a5ddcd39
User: Marek Fukala <mfukala@netbeans.org>
Log: #135153 - ClassCastException: org.mozilla.javascript.Node cannot be cast to org.mozilla.javascript.Node$StringNode