You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "nmatt (via GitHub)" <gi...@apache.org> on 2025/11/05 17:02:20 UTC
[I] Find Usages / Call Hierarchy fails with StringIndexOutOfBoundsException on enum constructor [netbeans]
nmatt opened a new issue, #8985:
URL: https://github.com/apache/netbeans/issues/8985
### Apache NetBeans version
Apache NetBeans 28 latest release candidate
### What happened
Invoking Find Usages or Call Hierarchy on an enum constructor fails with a StringIndexOutOfBoundsException if the enum type has constants with implementations (curly braces).
Exception stacktrace:
```
java.lang.StringIndexOutOfBoundsException: Range [74, -1) out of bounds for length 115
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:112)
at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:349)
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4865)
at java.base/java.lang.String.substring(String.java:2834)
at java.base/java.lang.String.subSequence(String.java:2872)
at org.netbeans.modules.refactoring.java.WhereUsedElement.create(WhereUsedElement.java:303)
at org.netbeans.modules.refactoring.java.WhereUsedElement.create(WhereUsedElement.java:162)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.addUsage(FindUsagesVisitor.java:336)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.addIfMatch(FindUsagesVisitor.java:218)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.visitIdentifier(FindUsagesVisitor.java:371)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.visitIdentifier(FindUsagesVisitor.java:50)
at com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2718)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at com.sun.source.util.TreeScanner.visitMethodInvocation(TreeScanner.java:591)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1876)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.visitExpressionStatement(TreeScanner.java:504)
at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1655)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at com.sun.source.util.TreeScanner.visitBlock(TreeScanner.java:271)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1148)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at com.sun.source.util.TreeScanner.visitMethod(TreeScanner.java:223)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:992)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:118)
at com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:202)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:899)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at com.sun.source.util.TreeScanner.visitNewClass(TreeScanner.java:611)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.visitNewClass(FindUsagesVisitor.java:405)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.visitNewClass(FindUsagesVisitor.java:50)
at com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1937)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:95)
at com.sun.source.util.TreeScanner.visitVariable(TreeScanner.java:242)
at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1084)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:118)
at com.sun.source.util.TreeScanner.visitClass(TreeScanner.java:202)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:899)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at com.sun.source.util.TreeScanner.scan(TreeScanner.java:110)
at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:118)
at com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:151)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.visitCompilationUnit(FindUsagesVisitor.java:135)
at org.netbeans.modules.refactoring.java.plugins.FindUsagesVisitor.visitCompilationUnit(FindUsagesVisitor.java:50)
at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:627)
at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:92)
at org.netbeans.modules.refactoring.java.callhierarchy.CallHierarchyTasks$CallersTask.run(CallHierarchyTasks.java:357)
at org.netbeans.modules.refactoring.java.callhierarchy.CallHierarchyTasks$CallersTask.run(CallHierarchyTasks.java:301)
at org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:504)
at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:586)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:197)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:180)
at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:181)
at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:178)
at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:153)
at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:335)
at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:118)
at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:67)
at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:178)
at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:83)
at org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:454)
at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:425)
at org.netbeans.modules.refactoring.java.callhierarchy.CallHierarchyTasks$CallersTask.processFiles(CallHierarchyTasks.java:476)
at org.netbeans.modules.refactoring.java.callhierarchy.CallHierarchyTasks$CallersTask.runTask(CallHierarchyTasks.java:338)
[catch] at org.netbeans.modules.refactoring.java.callhierarchy.CallHierarchyTasks$CallTaskBase.run(CallHierarchyTasks.java:288)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1403)
at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018)
```
### Language / Project Type / NetBeans Component
Java, Refactoring
### How to reproduce
In a Java project, create the following enum class:
```
enum Example
{
CONSTANT() { };
Example() { }
}
```
Then invoke Find Usages or Call Hierarchy on `Example()`.
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows
### JDK
21
### Apache NetBeans packaging
Apache NetBeans binary zip
### Anything else
This might not be a common operation for enum constructors, but in large enum classes (constants with non-trivial implementations), it can actually be quite useful. Another reason is that that having the cursor on the enum constructor doesn't highlight the constants in the sidebar, unlike other usages.
### Are you willing to submit a pull request?
No
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [I] Find Usages / Call Hierarchy fails with StringIndexOutOfBoundsException on enum constructor [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on issue #8985:
URL: https://github.com/apache/netbeans/issues/8985#issuecomment-3499839602
I might have found a fix, the bad news is that the find-usage tests were disabled at some point in past.
test build: https://github.com/apache/netbeans/actions/runs/19152847040/artifacts/4493694118
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [I] Find Usages / Call Hierarchy fails with StringIndexOutOfBoundsException on enum constructor [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on issue #8985:
URL: https://github.com/apache/netbeans/issues/8985#issuecomment-3500398712
yeah there are likely more problems with it which go beyond the span computation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [I] Find Usages / Call Hierarchy fails with StringIndexOutOfBoundsException on enum constructor [netbeans]
Posted by "nmatt (via GitHub)" <gi...@apache.org>.
nmatt commented on issue #8985:
URL: https://github.com/apache/netbeans/issues/8985#issuecomment-3500047161
@mbien: Thanks, I tried out the test build. The exception is fixed, but the results display is a bit broken. I changed the example to:
```java
enum Example
{
FOO,
BAR(),
BAZ() { };
Example() { }
}
```
In the Call Hierarchy result (see below), the constant names are missing for subclass constants. Expanding the "()" node also shows nothing further.
In the Find Usages result, the internal symbol caching is faulty, displaying the previous identifier "CONSTANT" that I had edited (and saved the changes). When removing the parentheses after "BAR", the "CONSTANT" moves down to "BAZ" in the Find Usages results.
Find Usages:
<img width="201" height="131" alt="Image" src="https://github.com/user-attachments/assets/b0c05a41-8c0b-4460-a22e-8c9fd6d36170" />
Call Hierarchy:
<img width="186" height="76" alt="Image" src="https://github.com/user-attachments/assets/10b987bc-581c-42e5-a8b4-78a1c5cb4537" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [I] Find Usages / Call Hierarchy fails with StringIndexOutOfBoundsException on enum constructor [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien closed issue #8985: Find Usages / Call Hierarchy fails with StringIndexOutOfBoundsException on enum constructor
URL: https://github.com/apache/netbeans/issues/8985
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists