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 222028 - After "convert to try-with-resources", identation is wrong
Summary: After "convert to try-with-resources", identation is wrong
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
: 217820 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-11-13 11:18 UTC by ecerichter
Modified: 2013-01-08 09:09 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Incorrect code formating after applying the hint (16.46 KB, image/png)
2012-11-13 11:20 UTC, ecerichter
Details
The wrong identation after "convert to switch" (22.02 KB, image/png)
2012-11-18 21:23 UTC, ecerichter
Details
expected identation according to the formating rules (22.44 KB, image/png)
2012-11-18 21:23 UTC, ecerichter
Details
Exported format rules (1.88 KB, application/zip)
2012-11-19 11:18 UTC, ecerichter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ecerichter 2012-11-13 11:18:34 UTC
Product Version = NetBeans IDE Dev (Build 201211110001)
Operating System = Windows 7 version 6.1 running on amd64
Java; VM; Vendor = 1.7.0_09
Runtime = Java HotSpot(TM) 64-Bit Server VM 23.5-b02

Create the code:

    if(boletosId.length==0) {
      response.setContentType("text/plain");
      PrintWriter pw = response.getWriter();
      pw.println("Nenhum identificador de boleto fornecido. A operação foi cancelada.");
      pw.flush();
      pw.close();
    }

at line "PrintWriter pw...", NetBeans give the hint "Convert to try-with-resources". Developer accept the hint, and everything is idented out of current rules:

    if(boletosId.length==0) {
      response.setContentType("text/plain");
              try (PrintWriter pw = response.getWriter()) {
                pw.println("Nenhum identificador de boleto fornecido. A operação foi cancelada.");
                pw.flush();
              }
    }

See attached screenshot for a more "visual clue" of the issue.

Regards,

Edson
Comment 1 ecerichter 2012-11-13 11:20:41 UTC
Created attachment 127700 [details]
Incorrect code formating after applying the hint

Note: if developer uses Source -> Format, then everything is correctly formatted, so it seems to be a issue with hint detector.
Comment 2 ecerichter 2012-11-18 21:21:01 UTC
Same happens when I apply the "convert to Switch" hint for (if-the-else with strings).
Comment 3 ecerichter 2012-11-18 21:23:19 UTC
Created attachment 128018 [details]
The wrong identation after "convert to switch"
Comment 4 ecerichter 2012-11-18 21:23:43 UTC
Created attachment 128019 [details]
expected identation according to the formating rules
Comment 5 Jan Lahoda 2012-11-19 09:10:27 UTC
I tried to reproduce, but unfortunately did not succeed - are there some particular steps that would allow me to reproduce the bug? Thanks.
Comment 6 ecerichter 2012-11-19 11:17:39 UTC
Well, I don't know.
It happens always for me.
Maybe something special in my formatting rules?

See exported formatting rules in the attachment.
Comment 7 ecerichter 2012-11-19 11:18:19 UTC
Created attachment 128045 [details]
Exported format rules
Comment 8 Jan Lahoda 2012-11-19 12:18:00 UTC
Unfortunately, still not luck. Jirka, could you please try? Thanks.
Comment 9 Jiri Prox 2012-11-21 14:00:19 UTC
Unfortunately I cannot reproduce it as well, even when importing the formatting settings
Comment 10 ecerichter 2012-11-21 14:18:10 UTC
Ok, I've been using the same .netbeans dir since 7.2.
I'll make a test with a fresh install, and let you know the results.

Thanks,

Edson
Comment 11 Jan Lahoda 2012-11-23 08:59:16 UTC
I think I may know what is the problem. Could you please check if you have multi-line method header or multi-line condition in if/while/... enclosing the part of the code where the change is being applied? E.g.:
    public boolean foo(String name,
                       String path) {//multi-line method header.
        {
            if (name.equals("a")) {
                System.err.println("a");
            } else if (name.equals("b")) {
                System.err.println("b");
            }
        }
        return path.equals("bin");
    }

Thank you.
Comment 12 ecerichter 2012-11-23 10:15:11 UTC
(In reply to comment #11)
> I think I may know what is the problem. Could you please check if you have
> multi-line method header or multi-line condition in if/while/... enclosing the
> part of the code where the change is being applied? E.g.:
>     public boolean foo(String name,
>                        String path) {//multi-line method header.
>         {
>             if (name.equals("a")) {
>                 System.err.println("a");
>             } else if (name.equals("b")) {
>                 System.err.println("b");
>             }
>         }
>         return path.equals("bin");
>     }
> 
> Thank you.

Yes, this is true.
All the cases match multi line methods declaration.

Thanks,

Edson
Comment 13 Quality Engineering 2012-11-25 03:10:37 UTC
Integrated into 'main-golden', will be available in build *201211250002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/85fb6c59d3eb
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #222028: infer the indent level from the first member of a block/class instead of the indent of the block/class itself
Comment 14 Jan Lahoda 2012-11-26 09:14:20 UTC
The above patch fixes the problem - thank you for the report.
Comment 15 Jan Lahoda 2013-01-08 09:09:49 UTC
*** Bug 217820 has been marked as a duplicate of this bug. ***