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 92726 - StringIndexOutOfBoundsException when trying to implement interface methods
Summary: StringIndexOutOfBoundsException when trying to implement interface methods
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-17 17:51 UTC by Torbjorn Norbye
Modified: 2007-02-01 14:30 UTC (History)
0 users

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-01-17 17:51:56 UTC
I had an anonymous class implementation of an interface that was missing a
method I had just added to the interface. When I tried to invoke the Quickfix to
implement the method, I got the following SIOOBE.

The method call looked like this:

                    SourceFileReader reader = new SourceFileReader() {
                        public CharSequence read(ParserFile fileObject) {
                            assert fileObject.getFileObject() == bufferFo;
                            return buffer;
                        }
                        
                    };

I invoked the quickfix on the first line, to add the new method int getFoo().

java.lang.StringIndexOutOfBoundsException: String index out of range: -7345
	at java.lang.String.substring(String.java:1768)
	at org.netbeans.modules.java.source.save.CasualDiff.copyTo(CasualDiff.java:2368)
	at
org.netbeans.modules.java.source.save.CasualDiff.diffMethodDef(CasualDiff.java:464)
	at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:2003)
	at org.netbeans.modules.java.source.save.CasualDiff.diffList(CasualDiff.java:1698)
	at
org.netbeans.modules.java.source.save.CasualDiff.diffClassDef(CasualDiff.java:414)
	at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:2000)
	at org.netbeans.modules.java.source.save.CasualDiff.diffList(CasualDiff.java:1698)
	at
org.netbeans.modules.java.source.save.CasualDiff.diffTopLevel(CasualDiff.java:218)
	at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:1994)
	at org.netbeans.modules.java.source.save.CasualDiff.diffTree(CasualDiff.java:2183)
	at org.netbeans.modules.java.source.save.CasualDiff.diff(CasualDiff.java:115)
	at org.netbeans.modules.java.source.save.Commit.commit(Commit.java:234)
	at
org.netbeans.modules.java.source.save.Commit.visitCompilationUnit(Commit.java:174)
	at
org.netbeans.modules.java.source.save.Commit.visitCompilationUnit(Commit.java:64)
	at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:476)
	at org.netbeans.modules.java.source.engine.RootTree.accept(RootTree.java:60)
	at org.netbeans.api.java.source.query.Query.apply(Query.java:128)
	at org.netbeans.modules.java.source.save.Commit.commit(Commit.java:117)
	at org.netbeans.api.java.source.WorkingCopy.getChanges(WorkingCopy.java:305)
	at org.netbeans.api.java.source.JavaSource.runModificationTask(JavaSource.java:555)
	at
org.netbeans.modules.java.hints.ImplementAllAbstractMethodsCreator$FixImpl.implement(ImplementAllAbstractMethodsCreator.java:165)
	at org.netbeans.modules.editor.hints.HintsUI$1.run(HintsUI.java:498)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:541)
[catch] at
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:963)
Comment 1 Pavel Flaska 2007-01-17 19:21:47 UTC
Please provide the build number. I was unable to reproduce the issue in current
build. If you are able to reproduce it in current trunk build, try to provide
both sources, SourceFileReader and the source where exception occured.
Comment 2 Pavel Flaska 2007-01-31 14:58:00 UTC
I tried it again and was not able to reproduce it. Check that it works for you,
marking WORKSFORME. Reopen with additional information if you are able to
reproduce it.
Comment 3 Torbjorn Norbye 2007-01-31 17:12:31 UTC
I couldn't really boil the example down and still get it to break.

So I've been waiting to submit files because I was moving my files to the
NetBeans CVS repository; they're there now so you can reproduce this for yourself.

Check out the scripting module in CVS, then open the NetBeans module
scripting/gsf/.   Open org.netbeans.api.retouche.source.Source  (you might
recognize it as a modified version of JavaSource in java/source/).  Scan for the
line "new SourceFileReader", and in that inner class, remove the whole method
definition for getCaretOffset(ParserFile).  You'll now get a quickfix to
implement all interfaces. When you do that, you still get the same exception
(with trunk sources as of yesterday).
Comment 4 Pavel Flaska 2007-01-31 17:17:27 UTC
Thanks for the steps, I'll investigate it.
Comment 5 Pavel Flaska 2007-02-01 09:40:42 UTC
Yes, reproducible.
Comment 6 Pavel Flaska 2007-02-01 10:39:48 UTC
Try to remove semicolon at the end of enum Priority (line 132). Then, it will
work like a charm. No, it the tip was joke. (It will work, but definitely it has
to be fixed.) I solved similar problem with syntetic constructors and not
available super() calls. The semicolon is redundant and represented like a
initializer block {}, which is member of class, but it does not have position
defined.

Seems that the root cause is the same as #92127, but still leaving both issues
opened.
Comment 7 Pavel Flaska 2007-02-01 14:30:57 UTC
Checking in src/org/netbeans/modules/java/source/save/CasualDiff.java;
/cvs/java/source/src/org/netbeans/modules/java/source/save/CasualDiff.java,v 
<--  CasualDiff.java
new revision: 1.56; previous revision: 1.55
done
Checking in src/org/netbeans/modules/java/source/save/PositionEstimator.java;
/cvs/java/source/src/org/netbeans/modules/java/source/save/PositionEstimator.java,v
 <--  PositionEstimator.java
new revision: 1.6; previous revision: 1.5
done