Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 158150 - Error in rewriting of UnaryTree
Error in rewriting of UnaryTree
Product: java
Classification: Unclassified
Component: Source
All All
: P3 (vote)
: 6.x
Assigned To: Rastislav Komara
Depends on:
  Show dependency treegraph
Reported: 2009-02-08 12:22 UTC by tronicek
Modified: 2009-05-23 06:55 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT

test case, no fix yet (2.16 KB, patch)
2009-05-10 20:40 UTC, fommil
Details | Diff
(updated, bug in previous) test case, no fix yet (1.98 KB, text/plain)
2009-05-11 22:04 UTC, fommil
added second failing test case (3.45 KB, text/plain)
2009-05-14 22:22 UTC, fommil
2 test cases and proposed fix (5.03 KB, text/plain)
2009-05-16 18:22 UTC, fommil

Note You need to log in before you can comment on or make changes to this bug.
Description tronicek 2009-02-08 12:22:17 UTC
I am trying to rewrite - - x to + x:

            UnaryTree node2 = (UnaryTree) node;
            UnaryTree original = (UnaryTree) node2.getExpression();
            modified = make.Unary(Kind.UNARY_PLUS, original.getExpression());
            System.out.println("original: " + node);
            System.out.println("modified: " + modified);
            wc.rewrite(node, modified);

The log contains what I expected:

original: --x
modified: +x

But the source is changed from

    int y = - - x;


    int y + - x;
Comment 1 Rastislav Komara 2009-02-16 10:37:11 UTC
Comment 2 fommil 2009-05-10 20:40:38 UTC
Created attachment 81866 [details]
test case, no fix yet
Comment 3 fommil 2009-05-11 12:22:16 UTC
I'd like to NetFIX [1] this bug. Is it possible? [1]
Comment 4 Rastislav Komara 2009-05-11 12:37:49 UTC
Probably yes. Look at handling diff of unary expression in CasualDiff.
Comment 5 fommil 2009-05-11 22:04:11 UTC
Created attachment 81926 [details]
(updated, bug in previous) test case, no fix yet
Comment 6 fommil 2009-05-12 21:24:49 UTC
I believe the bug is on the line

int[] argBounds = getBounds(oldT.arg);

in CasualDiff.diffUnary. It appears to be returning the wrong argBounds[0], being off by one. The oldT.arg refers to "-x" in this case, not "--x". Some 
additional logic is required.
Comment 7 fommil 2009-05-14 22:21:20 UTC
OK, I think I found *another* problem with the Unary differ... it doesn't handle cases where the unary operator changes left/right ordering. A UnaryTree can 
have pre and post operators. e.g. --c, c++. I'm attaching a new diff which includes a new failing test case.

Hmm... here's a dumb question, but why do we go to all this effort to write out what a Tree means, when the toString() methods already do all the work for 
us? Is it because the toString() is ill-defined? If so, that's a bit of a poor excuse, because there are lots of examples of precedent (especially in the hinter) 
where the toString() method of Trees are used.
Comment 8 fommil 2009-05-14 22:22:17 UTC
Created attachment 82159 [details]
added second failing test case
Comment 9 fommil 2009-05-16 18:22:37 UTC
Created attachment 82238 [details]
2 test cases and proposed fix
Comment 10 fommil 2009-05-16 18:25:14 UTC
I believe java.source-158150-4.patch fixes this bug! :-) Ready for review.

The problem was that the current code forgot that the operator can be on either side of the expression, forgetting that (most!) unary operators are actually on 
the left of the expression, hence inappropriate copyTo calls.
Comment 11 Rastislav Komara 2009-05-22 10:45:59 UTC
Comment 12 Rastislav Komara 2009-05-22 15:21:50 UTC
jet-main #5e5aa9deaa08
Comment 13 Quality Engineering 2009-05-23 06:55:11 UTC
Integrated into 'main-golden', will be available in build *200905230201* on (upload may still be in progress)
User: Rastislav Komara <>
Log: #158150: Error in rewriting of UnaryTree

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo