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 111510 - AIOOBE when switching to Logical view
Summary: AIOOBE when switching to Logical view
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords: I18N
Depends on:
Blocks:
 
Reported: 2007-07-31 16:25 UTC by Jiri Prox
Modified: 2007-10-25 13:43 UTC (History)
1 user (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 Jiri Prox 2007-07-31 16:25:43 UTC
Product Version: NetBeans IDE Dev (Build 200707270000) Java: 1.5.0_12; Java HotSpot(TM) Client VM 1.5.0_12-b04 System: 
Linux version 2.6.5-1.358 running on i386 UTF-8; ja_JP (nb) Userdir: /space/ui18n3


AIOOBE is thrown when switching to logical view in the rename refactoring preview. This can be only reproduced with
pseudolocalized build.

Steps to reporduce:
1) have a code:
def meth
  puts "Method"
end

puts "Hello World"
meth

2) rename method meth
3) in preview click on the Logical view button
->

java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at org.netbeans.modules.refactoring.java.ui.tree.FolderTreeElement.getSourceGroup(FolderTreeElement.java:99)
	at org.netbeans.modules.refactoring.java.ui.tree.TreeElementFactoryImpl.getTreeElement(TreeElementFactoryImpl.java:54)
	at org.netbeans.modules.refactoring.spi.ui.TreeElementFactory.getTreeElement(TreeElementFactory.java:44)
	at org.netbeans.modules.refactoring.java.ui.tree.FileTreeElement.getParent(FileTreeElement.java:47)
	at org.netbeans.modules.refactoring.spi.impl.RefactoringPanel.createNode(RefactoringPanel.java:412)
	at org.netbeans.modules.refactoring.spi.impl.RefactoringPanel.createNode(RefactoringPanel.java:417)
	at org.netbeans.modules.refactoring.spi.impl.RefactoringPanel.access$800(RefactoringPanel.java:64)
	at org.netbeans.modules.refactoring.spi.impl.RefactoringPanel$5.run(RefactoringPanel.java:662)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:539)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:964)
Comment 1 Torbjorn Norbye 2007-07-31 16:37:27 UTC
In looking at the stack trace this is coming from the Java refactoring module.  The "getSourceGroup" method needs to tolerate being called on project types 
where it doesn't find java sources.  (I fixed something similar in the Ruby copy myself.)

(I don't think this is I18N related)

Here's the Java implementation:

    static SourceGroup getSourceGroup(FileObject file) {
        Project prj = FileOwnerQuery.getOwner(file);
        if (prj == null)
            return null;
        Sources src = ProjectUtils.getSources(prj);
        //TODO: needs to be generified
        SourceGroup[] javagroups = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        SourceGroup[] xmlgroups = src.getSourceGroups("xml");//NOI18N

        SourceGroup[] allgroups =  new SourceGroup[javagroups.length + xmlgroups.length];
        System.arraycopy(javagroups,0,allgroups,0,javagroups.length);
        System.arraycopy(xmlgroups,0,allgroups,allgroups.length-1,xmlgroups.length);
        for(int i=0; i<allgroups.length; i++) {
            if (allgroups[i].getRootFolder().equals(file) || FileUtil.isParentOf(allgroups[i].getRootFolder(), file))
                return allgroups[i];
        }
        return null;
    }


Here's what I now have for Ruby:

    static SourceGroup getSourceGroup(FileObject file) {
        Project prj = FileOwnerQuery.getOwner(file);
        if (prj == null)
            return null;
        Sources src = ProjectUtils.getSources(prj);
        //TODO: needs to be generified
        SourceGroup[] rubygroups = src.getSourceGroups(RubyProject.SOURCES_TYPE_RUBY);
        SourceGroup[] xmlgroups = src.getSourceGroups("xml");//NOI18N

        if (rubygroups.length == 0 && xmlgroups.length == 0) {
            // Probably used as part of some non-Ruby-related project refactoring operation (#106987)
            return null;
       }

        SourceGroup[] allgroups =  new SourceGroup[rubygroups.length + xmlgroups.length];
        System.arraycopy(rubygroups,0,allgroups,0,rubygroups.length);
        System.arraycopy(xmlgroups,0,allgroups,allgroups.length-1,xmlgroups.length);
        for(int i=0; i<allgroups.length; i++) {
            if (allgroups[i].getRootFolder().equals(file) || FileUtil.isParentOf(allgroups[i].getRootFolder(), file))
                return allgroups[i];
        }
        return null;
    }
Comment 2 Jan Becicka 2007-08-03 07:45:46 UTC
Checking in FolderTreeElement.java;
/cvs/refactoring/java/src/org/netbeans/modules/refactoring/java/ui/tree/FolderTreeElement.java,v  <-- 
FolderTreeElement.java
new revision: 1.6; previous revision: 1.5
done

I improved logging. There should be no exception thrown, but there should be error message in the console:
Cannot find SourceGroup for /some/file

And I like to know which file is the bad one.
Thanks
Comment 3 Jan Becicka 2007-08-10 10:42:14 UTC
Marking as fixed. Please reopen if it happens again
Comment 4 Jiri Prox 2007-10-25 13:43:12 UTC
v.