Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 158129 - Error in rewriting of CaseTree
Error in rewriting of CaseTree
Product: java
Classification: Unclassified
Component: Source
All All
: P3 (vote)
: 6.x
Assigned To: Rastislav Komara
Depends on:
  Show dependency treegraph
Reported: 2009-02-07 18:10 UTC by tronicek
Modified: 2009-05-14 13:06 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT

failing test case (4.08 KB, patch)
2009-05-05 23:12 UTC, fommil
Details | Diff
proposed bugfix and test case (5.71 KB, patch)
2009-05-08 20:00 UTC, fommil
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description tronicek 2009-02-07 18:10:57 UTC
When I rewrite a CaseTree using the following statements, I will get a wrong result.

            CaseTree original = (CaseTree) node;
            List<StatementTree> st = new ArrayList<StatementTree>();
            modified = make.Case(original.getExpression(), st);
            System.out.println("original: " + node);
            System.out.println("modified: " + modified);
            wc.rewrite(node, modified);

    void m(int p) {
        switch (p) {
            case 0:

Wrong output:
    void m(int p) {
        switch (p) {
            case 0break ;

The problem is probably in the rewrite method because the trees are right before the rewriting.
original: case 0: 

modified: case 0: 
    break ;
Comment 1 Rastislav Komara 2009-02-16 10:33:59 UTC
Comment 2 fommil 2009-05-04 16:23:43 UTC
I'd like to NetFIX [1] this bug. Is it possible? [1]
Comment 3 fommil 2009-05-05 22:37:24 UTC
Notes from @jlahoda
Having a reproducible test case, this should not be very hard to fix. Most likely a bug in the code generator. Bugs in
code generator are typically fixed as follows:

- add one or more tests into the generator test suite (package in java.source's tests).
- fix the problem, so that the test passes.
- run whole codegen test suite by executing "ant -Dtest.config=generator test" inside java.source module. All tests must
pass (this test suite is being run during the jet-main continuous build, so all tests should be passing).
Comment 4 fommil 2009-05-05 22:45:56 UTC
@jlahoda... worth pointing out to others that TutorialTest has a lot of examples in it. I just stumbled across it!
Comment 5 fommil 2009-05-05 23:12:49 UTC
Created attachment 81596 [details]
failing test case
Comment 6 fommil 2009-05-06 21:30:01 UTC
This is a pesky one! Lots of code that needs to be understood.

I'm pretty sure the bug is in (or called from) CasualDiff.diff(Context, WorkingCopy, TreePath, JCTree, Map, Map, Map)
Comment 7 fommil 2009-05-08 20:00:00 UTC
Created attachment 81830 [details]
proposed bugfix and test case
Comment 8 fommil 2009-05-08 20:03:16 UTC
@moonko I'm not 100% happy with this bug fix. It comprises:-

- test case (now passes)
- add empty do {} to while statements (to make it explicit that this is not a typo!)
- the fix: add a tokenSequence.moveNext() to diffCase following the iteration to COLON

The reason I am not happy is that the whitespace is not coming out right. I expect a space to be entered between the "case:break;" and no newline afterward. 
Please amend the testcase if you wish to also test this.
Comment 9 Rastislav Komara 2009-05-11 12:00:58 UTC
Patch accepted. jet-main #c77f10c5666e
Comment 10 Quality Engineering 2009-05-12 07:42:41 UTC
Integrated into 'main-golden', will be available in build *200905120201* on (upload may still be in progress)
User: Rastislav Komara <>
Log: #158129: Error in rewriting of CaseTree
Comment 11 Jiri Kovalsky 2009-05-14 13:06:24 UTC
Adding NETFIX keyword.

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