Bug 419829 - [1.8] Error marker not updated correctly after undo
Summary: [1.8] Error marker not updated correctly after undo
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 424164 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-10-18 06:38 EDT by Noopur Gupta CLA
Modified: 2018-02-16 07:08 EST (History)
9 users (show)

See Also:


Attachments
Screenshot (27.88 KB, image/png)
2013-10-18 06:38 EDT, Noopur Gupta CLA
no flags Details
Screenshot with latest code (5.79 KB, image/png)
2013-12-02 03:43 EST, Noopur Gupta CLA
no flags Details
WIP: Patch (3.79 KB, patch)
2013-12-10 08:30 EST, shankha banerjee CLA
no flags Details | Diff
Jar file zip (13.87 KB, application/octet-stream)
2013-12-10 08:31 EST, shankha banerjee CLA
no flags Details
Source file zip (9.49 KB, application/octet-stream)
2013-12-10 08:32 EST, shankha banerjee CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2013-10-18 06:38:44 EDT
Created attachment 236644 [details]
Screenshot

package one.test;

import java.lang.annotation.Repeatable;

@interface FooContainerContainer {
	FooContainer[] value();
}

@Repeatable(FooContainerContainer.class)
@interface FooContainer {
	Foo[] value() default {};
}

@Repeatable(FooContainer.class)
@interface Foo {
	int value();
}

@Foo(0)
@FooContainer({ @Foo(1) })
@FooContainer({ @Foo(2) })
public class A3 {

}
------------------------------------
1. File is initially saved with error at '@Foo(0)'
2. Delete the '@Foo(0)' line. Editor is dirty.
3. Add semicolon at the end of '@FooContainer({ @Foo(1) })'
4. Press Ctrl+Z twice. Editor is not dirty anymore. But the error marker (sometimes red and mostly gray) at '@FooContainer({ @Foo(1) })' stays.
(See attached screenshot)
Comment 1 Srikanth Sankaran CLA 2013-12-01 09:06:12 EST
This is not reproducible anymore - I could and did reproduce it when it was
reported. Closing as WORKSFORME.

Noopur, please test against the HEAD of BETA_JAVA8 and if you are also
not able to reproduce - please mark as verified. Otherwise reopen. Thanks.
Comment 2 Noopur Gupta CLA 2013-12-02 03:43:20 EST
Created attachment 237892 [details]
Screenshot with latest code

Now with the latest code, I can see a warning instead of error at '@Foo(0)'.
And playing with the steps given in comment #0, I still see different markers as attached in the screenshot.
Comment 3 Srikanth Sankaran CLA 2013-12-02 03:51:34 EST
Thanks Noopur, don't know what is going on - will take a look.
Comment 4 shankha banerjee CLA 2013-12-10 08:30:14 EST
Created attachment 238201 [details]
WIP: Patch

I can reproduce the issue. I have trouble coming up with a test case where I can reproduce the bug problematically.

I am attaching the WIP patch. Can one of you help with the test case.

I will attach the jclMin1.8src.jar and jclMin1.8src.zip files needed.

The following file:

Repeatable.class and Repeatable.java have been added. 
Path : src\java\lang\annotation

Thanks
Comment 5 shankha banerjee CLA 2013-12-10 08:31:27 EST
Created attachment 238202 [details]
Jar file zip

Please see Comment 4
Comment 6 shankha banerjee CLA 2013-12-10 08:32:14 EST
Created attachment 238203 [details]
Source file zip

Please see Comment 4.
Comment 7 Srikanth Sankaran CLA 2014-02-03 02:47:49 EST
I have observed as well as we have heard reports from Markus and Noopur
that some times, the reconciler ends up with incorrect source ranges for
constructs. These are not consistently reproducible.

In my observation, one or more of 

    - Pasting snippets into editor or package explorer,
    - quick fix/refactoring.
    - Undo/Redo
    - Incremental build/clean build
    - Change of project settings (compliance/source levels in particular)
may be involved.

The observed symptoms are one or more of :

    - Editor shows persisting error which will vanish after a save, or some
other operation.
    - Package explorer will show the project having errors while it does not
    - Bad AST structure exceptions
    - Editor highlighting of erroroenous constructs is off by a few characters
here and there

These usually vanish with one or more of:

    - Save editor,
    - Clean and rebuild,
    - Refresh workspace
    - Shutdown and start eclipse.

We need to track this loch ness mosnter and shoot it down in time for GA.
Comment 8 Srikanth Sankaran CLA 2014-02-03 02:48:37 EST
*** Bug 424164 has been marked as a duplicate of this bug. ***
Comment 9 Srikanth Sankaran CLA 2014-02-03 02:52:18 EST
We need reproducible test cases. If you spot any weird issues in this
area, please document your observations/steps here.
Comment 10 Timo Kinnunen CLA 2014-02-03 07:35:24 EST
I've seen a couple like that related to naming and renaming of compilation units. First one involves one CU with two classes, one of them public. After editing the source to make the public class package-private and the other one public instead the CU remains tied to the formerly public class. 

Second one seemed much more serious and happened with two classes A and B in separate CUs. After renaming class A->C and class B->A Package Explorer showed the contents of the new A correctly but the editor view of A showed the old contents of the former A, now C, and these contents didn't seem to be tied to anything anymore. Only restarting cleared this.

I haven't tried to find the exact steps for these yet, but hopefully there aren't any edge-case conditions that are needed for them to occur.
Comment 11 Srikanth Sankaran CLA 2014-02-18 13:33:13 EST
I don't see this problem anymore. Yes, I have claimed that before :)

Noopur, can you double check ?
Comment 12 Srikanth Sankaran CLA 2014-02-18 13:33:56 EST
(In reply to Srikanth Sankaran from comment #11)

> Noopur, can you double check ?

Screen shots not necessary, your word is proof enough :)
Comment 13 Noopur Gupta CLA 2014-02-18 14:05:02 EST
(In reply to Srikanth Sankaran from comment #12)
> (In reply to Srikanth Sankaran from comment #11)
> 
> > Noopur, can you double check ?
> 
> Screen shots not necessary, your word is proof enough :)

Yes, I can reproduce the issue in comment #0 with latest code of BETA_JAVA8.
The error/warning marker and its color varies depending on how fast I press Ctrl+z and whether I save the editor with code having error and then undo the changes.
Comment 14 Srikanth Sankaran CLA 2014-02-18 14:12:59 EST
(In reply to Noopur Gupta from comment #13)

> Ctrl+z and whether I save the editor with code having error and then undo
> the changes.

Thanks, the save operation seems to be essential. I can see it now.
Comment 15 Markus Keller CLA 2014-02-21 06:36:13 EST
See also bug 423416, which is about sporadically failing CodeCompletionTests. We can't explain why they sometimes fail, but the issue seems to be that the working copy buffer contains outdated contents.
Comment 16 Srikanth Sankaran CLA 2014-02-22 22:41:10 EST
(In reply to Noopur Gupta from comment #13)

> Yes, I can reproduce the issue in comment #0 with latest code of BETA_JAVA8.
> The error/warning marker and its color varies depending on how fast I press
> Ctrl+z and whether I save the editor with code having error and then undo
> the changes.

However, when you save and then do ^Z, the editor is tagged as dirty - right ?
If so, I don't see an issue here - unless you see a red circle when you should
not. I see only the grayed out circle after save and undo.
Comment 17 Srikanth Sankaran CLA 2014-02-22 22:44:31 EST
(In reply to Markus Keller from comment #15)
> See also bug 423416, which is about sporadically failing
> CodeCompletionTests. We can't explain why they sometimes fail, but the issue
> seems to be that the working copy buffer contains outdated contents.

Thanks, sounds plausible. I am retargetting this 4.4 - it is not clear that
JDT/core has a role here. If evidence emerges to the contrary, will pull it
back up.

The comment#0 scenario itself is not hugely worrisome for me - it is the
other scenarios listed - but I haven't spotted this lately.
Comment 18 Srikanth Sankaran CLA 2014-02-23 20:06:14 EST
Here is a scenario that shows the problem consistently. Basically, if you answer
yes to the dialog that says "... project settings have changed, do you want to
rebuild ?" when the editor is dirty, then the build seems to operate on the
old contents, while the editor is showing new contents.

Steps: 

- Start with Kepler SR + Java 8 bundles.
- Create a 1.8 project with the code below:

// --
interface I {
	void doit();
}

class X {
	static void foo() {}
	I i = (I & java.io.Serializable) () -> {};
	I i2 = new I() {
		public void doit() { 
			 
		}
	};
}

// compiles fine, no issues.
-- Replace the contents of the editor by copy + pasting the code below:

import java.io.File;

public class X {

  static interface IInterface {
    public void method(File file);
  }

  static abstract class AbstractClass implements IInterface {

    public void method(File file) {
      System.err.println("file");
    }

    public void method(String string) {
      System.err.println("string");
    }
  }

  private static AbstractClass newAbstractClass() {
    return new AbstractClass() {};
  }

  public static void main(String[] args) {
    // this should be flagged as ambiguous, but is not
    // correctly reported by javac as an error
    newAbstractClass().method(null);
  }
}
// Reconciler shows one error - good.

-- Without saving the file, go to project + properties + Java compiler + 
change compliance level, source level etc to 1.7 + apply

-- Answer yes to the rebuild now question.

-- You can see problems view reporting issues from the old file contents.
Editor shows the new file, error underlining is all messed up as the offets
etc are wrt to old file contents.

I am not sure whether this belongs in JDT/UI or Text.

Please pass it back if JDT/Core has a hand somewhere.
Comment 19 Srikanth Sankaran CLA 2014-02-23 20:23:02 EST
I opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=428858 for the
issues reported in 

https://bugs.eclipse.org/bugs/show_bug.cgi?id=419829#c7 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=419829#c18 

as it is very different from the issue reported in comment#0.

Let us keep the present defect only for the issue reported in comment#0.
Ignore all comments pertaining to more general weird issues in reconciler. 

Restored the original titled of the bug and assigning to JDT/Text for 
investigation. The phantom markers (grayed out ones) is what I see (when
I see) now and these are not managed by JDT/Core.

However, if analysis shows we have a hand somewhere, pass it back.
Comment 20 Noopur Gupta CLA 2014-02-26 05:04:35 EST
(In reply to Srikanth Sankaran from comment #16)
> (In reply to Noopur Gupta from comment #13)
> 
> > Yes, I can reproduce the issue in comment #0 with latest code of BETA_JAVA8.
> > The error/warning marker and its color varies depending on how fast I press
> > Ctrl+z and whether I save the editor with code having error and then undo
> > the changes.
> 
> However, when you save and then do ^Z, the editor is tagged as dirty - right
> ?
> If so, I don't see an issue here - unless you see a red circle when you
> should
> not. I see only the grayed out circle after save and undo.

After save, when I press Ctrl+Z twice very quickly, the editor is dirty and I also see the red circle at "@FooContainer({ @Foo(1) })".
Comment 21 Noopur Gupta CLA 2018-02-16 07:08:33 EST
I don't see this issue anymore. Please re-open with updated steps if you can still reproduce it.