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 122076 - Find Usages on a constant declaration generates an NPE
Summary: Find Usages on a constant declaration generates an NPE
Status: VERIFIED FIXED
Alias: None
Product: ruby
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Torbjorn Norbye
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-16 01:01 UTC by Torbjorn Norbye
Modified: 2007-11-19 11:59 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Torbjorn Norbye 2007-11-16 01:01:24 UTC
Find Usages is broken on any constant declarations.  For example, create a new project, and in main.rb add this line

FOO="bar"

Now do right click on Foo and choose Find Usages => NPE and find usages aborts.
Comment 1 Torbjorn Norbye 2007-11-16 01:05:41 UTC
Fix is trivial and low risk.

Basically, the "getKind()" method in RubyElementCtx is given a JRuby AST node and asked what kind of node it is - a
class, a variable, a constant, a field, and so on.

This method fails to check for ConstantDeclNodes, it only checks ConstNodes. The fix is to just handle this case as well:

--- RubyElementCtx.java 30 Oct 2007 14:43:16 -0000      1.7
+++ RubyElementCtx.java 16 Nov 2007 01:02:32 -0000
@@ -255,6 +255,8 @@
                         kind = ElementKind.CONSTANT;
                     }
                 }
+            } else if (node instanceof ConstDeclNode) {
+                kind = ElementKind.CONSTANT;
             } else if (node instanceof GlobalVarNode || node instanceof GlobalAsgnNode) {
                 kind = ElementKind.GLOBAL;
             } else if (node instanceof InstVarNode || node instanceof InstAsgnNode ||


Martin, can you review this fix?
Jiri, do you agree to merge this to 6.0?


Fixed in trunk:
Checking in RubyElementCtx.java;
/cvs/ruby/refactoring/src/org/netbeans/modules/refactoring/ruby/RubyElementCtx.java,v  <--  RubyElementCtx.java
new revision: 1.8; previous revision: 1.7
done
Comment 2 Martin Krauskopf 2007-11-16 07:49:13 UTC
> Martin, can you review this fix?

I do not know this code. Sure, from narrow-scope view it looks good. A regression test would review it more than I can ;)
Comment 3 Jiri Skrivanek 2007-11-16 08:53:54 UTC
I verified the fix in trunk and I agree to merge it to 6.0.
Comment 4 Torbjorn Norbye 2007-11-17 17:22:28 UTC
Integrated in release60

Checking in refactoring/src/org/netbeans/modules/refactoring/ruby/RubyElementCtx.java;
/cvs/ruby/refactoring/src/org/netbeans/modules/refactoring/ruby/RubyElementCtx.java,v  <--  RubyElementCtx.java
new revision: 1.7.2.1; previous revision: 1.7
done
Comment 5 Jesse Glick 2007-11-18 15:58:24 UTC
The patch merged to the branch did not compile. You forgot to merge the import fix from rev 1.9.

Checking in ruby/refactoring/src/org/netbeans/modules/refactoring/ruby/RubyElementCtx.java;
/shared/data/ccvs/repository/ruby/refactoring/src/org/netbeans/modules/refactoring/ruby/RubyElementCtx.java,v  <-- 
RubyElementCtx.java
new revision: 1.7.2.2; previous revision: 1.7.2.1
done
Comment 6 Torbjorn Norbye 2007-11-18 16:26:53 UTC
Thanks, Jesse!
Comment 7 Jiri Skrivanek 2007-11-19 11:59:02 UTC
Verified in 6.0.