Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 529637

Summary: ArrayIndexOutOfBoundsException in TokenManager
Product: [Eclipse Project] JDT Reporter: Dmitry Katsubo <dma_k>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, noopur_gupta, stephan.herrmann
Version: 4.7.1   
Target Milestone: 4.16 M3   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Eclipse log
none
Screenshot none

Description Dmitry Katsubo CLA 2018-01-10 10:03:31 EST
Created attachment 272212 [details]
Eclipse log

Given Java snippet:

package com.test;

public class ControllerImpl {

    package com.test;

    public ControllerImpl() {
    }
}

causes ArrayIndexOutOfBoundsException in TokenManager. Every line in source is marked as erroneous and it is not possible to see what exactly caused the problem.

Expected that Eclipse can recover from syntax error in line "package com.test;"
Comment 1 Dmitry Katsubo CLA 2018-01-10 10:04:24 EST
Created attachment 272213 [details]
Screenshot
Comment 2 Jay Arthanareeswaran CLA 2018-01-10 23:53:13 EST
Recovery is a very complicated piece of the eclipse compiler and it's all automated. I am not sure we can do much about it.

Anyway, I also see another problem with this code: When I copy+paste this into package explorer, two types getting created - com.test.ControllerImpl and snippet.ControllerImpl.

Noopur, do you know what's causing this?
Comment 3 Noopur Gupta CLA 2018-01-11 03:21:09 EST
(In reply to Jay Arthanareeswaran from comment #2)
> Anyway, I also see another problem with this code: When I copy+paste this
> into package explorer, two types getting created - com.test.ControllerImpl
> and snippet.ControllerImpl.
> 
> Noopur, do you know what's causing this?

That's due to two package declarations in the code. PasteAction can be used to paste multiple CUs in one go which are identified by the beginning of a new package declaration.
Comment 4 Stephan Herrmann CLA 2018-01-11 05:50:03 EST
(In reply to Jay Arthanareeswaran from comment #2)
> Recovery is a very complicated piece of the eclipse compiler and it's all
> automated. I am not sure we can do much about it.

If we think this is a relevant use case, then we could add one or more rules to the grammar expecting package declarations in bogus locations so that parsing can hand-craft a dedicated error message and discard the package declaration in AST.

I say "relevant" because this approach certainly doesn't scale for all kinds of broken inputs.
Comment 5 Jay Arthanareeswaran CLA 2018-01-11 07:56:43 EST
(In reply to Noopur Gupta from comment #3)
> That's due to two package declarations in the code. PasteAction can be used
> to paste multiple CUs in one go which are identified by the beginning of a
> new package declaration.

Shouldn't they both go to the same package in that case? Just curious.
Comment 6 Noopur Gupta CLA 2018-01-11 11:35:44 EST
(In reply to Jay Arthanareeswaran from comment #5)
> (In reply to Noopur Gupta from comment #3)
> > That's due to two package declarations in the code. PasteAction can be used
> > to paste multiple CUs in one go which are identified by the beginning of a
> > new package declaration.
> 
> Shouldn't they both go to the same package in that case? Just curious.

I will have to debug it to find that out. Relevant code: PasteAction.TextPaster.parseCUs(IJavaProject javaProject, String text).
Comment 7 Noopur Gupta CLA 2018-01-11 11:58:42 EST
(In reply to Noopur Gupta from comment #6)
> (In reply to Jay Arthanareeswaran from comment #5)
> > (In reply to Noopur Gupta from comment #3)
> > > That's due to two package declarations in the code. PasteAction can be used
> > > to paste multiple CUs in one go which are identified by the beginning of a
> > > new package declaration.
> > 
> > Shouldn't they both go to the same package in that case? Just curious.
> 
> I will have to debug it to find that out. Relevant code:
> PasteAction.TextPaster.parseCUs(IJavaProject javaProject, String text).

Moved this discussion out to a separate bug 529691.
Comment 8 Eclipse Genie CLA 2020-04-23 00:52:49 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 9 Stephan Herrmann CLA 2020-04-23 08:04:46 EDT
Exception no longer occurs. Syntax errors are reported based on best-effort by definition. Hence WONTFIX looks OK to me.
Comment 10 Dmitry Katsubo CLA 2020-05-12 07:28:33 EDT
I confirm that error recovery works better now.
Comment 11 Stephan Herrmann CLA 2020-05-12 08:07:51 EDT
(In reply to Dmitry Katsubo from comment #10)
> I confirm that error recovery works better now.

thanks for confirming.