1

I'm trying to load a file in eclipse and I'm getting the following error:

enter image description here

I've loaded this file before without issue. I also have multiple version controlled versions of this file in different projects, and all of them get the same error. I haven't encountered any other files that cause the error. I can load that file just fine in any other text editor.

I've never seen this before. I Googled the issue and I saw a bunch of discussions of completely unrelated issues, which leads me to believe this is just a generic error and I have no idea how to debug it. Here's the full stack trace:

java.lang.StringIndexOutOfBoundsException: String index out of range: 63
    at java.lang.String.charAt(Unknown Source)
    at com.cb.eclipse.folding.java.calculation.UserDefinedRegionHelper.isSentinel(UserDefinedRegionHelper.java:53)
    at com.cb.eclipse.folding.java.calculation.UserDefinedRegionHelper.isOpeningSentinel(UserDefinedRegionHelper.java:29)
    at com.cb.eclipse.folding.java.calculation.CommentHelper.isUserDefinedSentinel(CommentHelper.java:90)
    at com.cb.eclipse.folding.java.calculation.CommentHelper.handle(CommentHelper.java:67)
    at com.cb.eclipse.folding.java.calculation.AbstractBlockStrategy.handle(AbstractBlockStrategy.java:93)
    at com.cb.eclipse.folding.java.calculation.CompositeCalculationStrategy.handle(CompositeCalculationStrategy.java:24)
    at com.cb.eclipse.folding.java.calculation.CommentPrefixStrategy.handle(CommentPrefixStrategy.java:64)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.computeProjections(JavaProjectionCalculator.java:230)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:96)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:108)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:108)
    at com.cb.eclipse.folding.java.calculation.JavaProjectionCalculator.findAnnotations(JavaProjectionCalculator.java:68)
    at com.cb.eclipse.folding.java.calculation.ProjectionChangeReconciler.reconstructAnnotations(ProjectionChangeReconciler.java:173)
    at com.cb.eclipse.folding.java.calculation.ProjectionChangeReconciler.initialize(ProjectionChangeReconciler.java:99)
    at com.cb.eclipse.folding.java.EnhancedJavaFoldingStructureProvider.initialize(EnhancedJavaFoldingStructureProvider.java:115)
    at com.cb.eclipse.folding.java.EnhancedJavaFoldingStructureProvider$ProjectionListener.projectionEnabled(EnhancedJavaFoldingStructureProvider.java:201)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.fireProjectionEnabled(ProjectionViewer.java:488)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.enableProjection(ProjectionViewer.java:536)
    at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.setVisibleDocument(JavaSourceViewer.java:681)
    at org.eclipse.jface.text.TextViewer.setDocument(TextViewer.java:2934)
    at org.eclipse.jface.text.source.SourceViewer.setDocument(SourceViewer.java:643)
    at org.eclipse.jface.text.source.projection.ProjectionViewer.setDocument(ProjectionViewer.java:375)
    at org.eclipse.jface.text.source.SourceViewer.setDocument(SourceViewer.java:591)
    at org.eclipse.ui.texteditor.AbstractTextEditor.initializeSourceViewer(AbstractTextEditor.java:4050)
    at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(AbstractTextEditor.java:3578)
    at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(StatusTextEditor.java:54)
    at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(AbstractDecoratedTextEditor.java:447)
    at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createPartControl(JavaEditor.java:3125)
    at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.createPartControl(CompilationUnitEditor.java:1502)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:151)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:341)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:898)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:879)
    at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:121)
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:345)
    at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:264)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55)
    at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:971)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:640)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:746)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:717)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:711)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:695)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$1.handleEvent(PartServiceImpl.java:99)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
    at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:186)
    at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
    at org.eclipse.swt.widgets.Display.syncExec(Display.java:4761)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:211)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
    at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
    at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
    at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
    at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:85)
    at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:59)
    at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
    at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:171)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:494)
    at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:458)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:724)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:396)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1166)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3234)
    at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3149)
    at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3131)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3126)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3090)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3080)
    at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:373)
    at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:179)
    at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:268)
    at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:233)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:275)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:251)
    at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.handleOpen(PackageExplorerActionGroup.java:376)
    at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart$4.open(PackageExplorerPart.java:538)
    at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:48)
    at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:854)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
    at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:851)
    at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1168)
    at org.eclipse.jface.viewers.StructuredViewer$6.handleOpen(StructuredViewer.java:1275)
    at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:278)
    at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.java:272)
    at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:313)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
ewok
  • 20,148
  • 51
  • 149
  • 254

5 Answers5

5

The code for the UserDefinedRegionHelper.isSentinel is there : https://github.com/al3xandru/coffee-bytes/blob/master/com.cb.eclipse.folding/src/com/cb/eclipse/folding/java/calculation/UserDefinedRegionHelper.java

And more especially :

ISourceReference reference = (ISourceReference) owner;

        String contents = reference.getSource();
        ISourceRange range = (ISourceRange)reference.getSourceRange();


        int correctedStart = start - range.getOffset();
        // Math.min should be redundant (no JavaElement should contain half of a comment)
        int correctedEnd = Math.min( (end - range.getOffset()) , range.getLength());

        //System.out.println("Checking for sentinel: " + contents.substring(correctedStart, correctedEnd));
        boolean keepScanning = true;
        int shift = correctedStart+2; // +2 refers to the // characters which we know we can remove

        while(keepScanning && shift <= correctedEnd) {
            char nextChar = contents.charAt(shift);

            if(nextChar != ' ' && nextChar != '\t') {
                keepScanning = false;               
            }
            else {
                shift++;
            }

        }

The exception happens at

char nextChar = contents.charAt(shift);

This code parse comment lines. So my guess would be that in this specific file, you have written a comment with a special character at the end... But without your source code it is hard to tell !

Coralie B
  • 593
  • 3
  • 11
0

By following the above I tried removing all the comments in my code, however that wasn't my issue. I actually found the issue to be

  private static final NavigableMap<Long, String> suffixes = new TreeMap<>();
static {
        suffixes.put(1_000L, "k");
        suffixes.put(1_000_000L, "M");
        suffixes.put(1_000_000_000L, "B");
        suffixes.put(1_000_000_000_000L, "T");
        suffixes.put(1_000_000_000_000_000L, "P");
        suffixes.put(1_000_000_000_000_000_000L, "E");
       }

Which actually compiles and works just fine not sure why though. =/

Hope it helps

Norbert
  • 809
  • 9
  • 13
0

I'm a bit late to the party, but for people having this problem now (me included), here is the solution

In the stack trace, it mentions:

...
 at com.cb.eclipse.folding.java.*
...

which indicates it is an issue with code folding.

You can verify this by closing the file, opening another (working) java file, disabling code folding, then re-opening the originial file. It should open with no problems.

The issue is caused by an incomplete comment at the end of a line. eg.

private boolean example = false; //

Removing the //, or adding a single character after it fixes the issue.

Community
  • 1
  • 1
Oliver Olding
  • 41
  • 1
  • 8
0

The answers from Oliver and Emilles pointed me in the right direction to solve my problem.

In my case, i could not open a java file. The editor would fail to load and show the following:

Failed to create the part's controls:

java.lang.NoClassDefFoundError: org/codehaus/groovy/eclipse/editor/GroovyAwareFoldingStructureProvider
....

It seems that eclipse was updated to the latest version, but the groovy editor was not updated. As Emilles says, this will cause problems. The two need to be in sync. It appears this will happen every time eclipse releases a major update. https://github.com/groovy/groovy-eclipse/issues/1319

Solution A

re-install groovy tools using a new update site. e.g. for Eclipse 2021-12 this is: https://dist.springsource.org/snapshot/GRECLIPSE/e4.22.

Solution B

Disabling folding or updating the plugin didn't solve the problem for me.
I had to actually uninstall the groovy tools and the groovy plugin.

To uninstall groovy plugins completely

In eclipse:

  • Go to Help / About Eclipse IDE / Installation Details / Installed Software
  • filter for groovy, and use the Uninstall... button to remove it
  • in Window / Preferences / Install/Update / Available Software Sites, search for greclipse and disable or remove any results.
  • shut down eclipse

Now we need to remove the plug-in files.
In windows:

  • go to %USERPROFILE%\.p2\pool\plugins
  • remove any file or folder starting with org.codehaus.groovy
  • remove any file or folder starting with org.eclipse.jdt.groovy.core

now start eclipse again.

Adrian C
  • 71
  • 3
0

I also faced the same issue and tried everything mentioned in other solutions like changing the default editor but a very simple solution worked for me which was updating the eclipse plugins/software enter image description here

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31854721) – Sumit Sharma May 28 '22 at 17:38