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 159981 - Error in rewriting of ModifiersTree
Summary: Error in rewriting of ModifiersTree
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P4 blocker (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-10 11:35 UTC by tronicek
Modified: 2016-07-07 07:17 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
test case, passes (3.27 KB, text/plain)
2009-05-23 19:32 UTC, fommil
Details
test case, fails (2.71 KB, text/plain)
2009-05-24 15:35 UTC, fommil
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tronicek 2009-03-10 11:35:03 UTC
I rewrite ModifiersTree as follows:

            ModifiersTree t = make.Modifiers(fla2, ann2);
            System.out.println("t: " + t);
            wc.rewrite(node, t);

In the log, I can see that t is as I expect:
t: @A2()
@A1()
static 

But in the result, A1 is missing:
    @A2
    static void m() { }
Comment 1 Rastislav Komara 2009-03-11 13:52:24 UTC
Lowering priority. This issues are very specific.
Comment 2 Rastislav Komara 2009-03-11 13:52:40 UTC
Lowering priority. This issues are very specific.
Comment 3 David Strupl 2009-03-31 16:09:21 UTC
Resolving all issues with milestone "future" as LATER. If you feel strongly that
it should be implemented please reopen and set the target milestone to "next".
Comment 4 tronicek 2009-04-01 08:00:22 UTC
I am working on a refactoring module and these bugs are crucial for it to work.
Comment 5 fommil 2009-05-18 23:20:30 UTC
@tronicek you're going to have to provide some more info before I can reproduce this.
Comment 6 fommil 2009-05-23 19:32:27 UTC
Created attachment 82698 [details]
test case, passes
Comment 7 fommil 2009-05-23 19:36:38 UTC
I've attached a test case... but it passes for me, so we're missing the exact conditions that cause this.

@tronicek can you please confirm that when you create your new ModifiersTree, that you are passing in the full list of flags (or the original tree) and BOTH 
annotations? The API documentation for make.Modifiers clearly states that you can pass in the original tree in order to use its FLAGS, but not its annotations... 
you need to pass both @A1 and @A2 to the method.
Comment 8 tronicek 2009-05-23 20:58:44 UTC
@fommil: sorry for delay, here it is:

                    ModifiersTree original = (ModifiersTree) node;
                    List<? extends AnnotationTree> ann = original.getAnnotations();
                    List<AnnotationTree> ann2 = new ArrayList<AnnotationTree>();
                    ann2.add(ann.get(1));
                    ann2.add(ann.get(0));
                    Set<Modifier> fla2 = original.getFlags();
                    modified = make.Modifiers(fla2, ann2);
                    logger.log(Level.INFO, "original: " + original);
                    logger.log(Level.INFO, "modified: " + modified);
                    wc.rewrite(original, modified);

I use the following input:

@interface A1 { }
@interface A2 { }

@A1
@A2
public class Test2 {

    @A1 @A2
    static void m() { }
}

The output is:

@A2
public class Test2 {

 @A2
    static void m() { }
}

which is incorrect. In the log, there is what I expect:

original: @A1()
@A2()
static 
modified: @A2()
@A1()
static
Comment 9 fommil 2009-05-24 15:29:07 UTC
OK, really weird bug... I'm able to reproduce *but* it appears to be a problem with the List used in generation, not in the diff code.

Uploading a test case that shows the breakage.
Comment 10 fommil 2009-05-24 15:35:49 UTC
Created attachment 82705 [details]
test case, fails
Comment 11 fommil 2009-05-24 15:36:32 UTC
OK, the issue is in the ordering of the annotations... works fine without the Collections.reverse() line in the test case but when reversed, code manifests itself.
Comment 12 Jan Lahoda 2009-08-20 10:02:21 UTC
Reassigning all moonko's java/source bugs to myself.
Comment 13 Peter Pis 2009-09-03 07:46:58 UTC
Everything seems to be clear, no extra info needed. Removing INCOMPLETE.
Comment 14 David Strupl 2012-10-25 13:41:45 UTC
Bug prior to 7.0, not touched for the last 2 years --> P4.
Comment 15 Martin Balin 2016-07-07 07:17:54 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss