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 114371 - [Introduce method] problem with initialization of variable
Summary: [Introduce method] problem with initialization of variable
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jan Lahoda
URL:
Keywords:
: 165780 179258 196658 197549 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-08-31 14:05 UTC by Jiri Prox
Modified: 2011-04-14 11:44 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Prox 2007-08-31 14:05:13 UTC
Product Version: NetBeans IDE Dev (Build 200708290343) Java: 1.6.0_02; Java HotSpot(TM) Client VM 1.6.0_02-b05 System:
Linux version 2.6.17-11-generic running on i386; UTF-8; en_US (nb) Userdir: /home/jp159440/.netbeans/dev

Introduce method hint can produce code which tries to return uninitialized variable.

Steps to reproduce:
1) have a code:
    public void method(boolean  arg) {
        int c = 0;        
        if(arg) c = 3;        
        System.out.println(c);        
    }

2) introduce method from the 2nd line ( if(arg)... )

-> 
    public void method(boolean  arg) {
        int c = 0;
        c = newMethod(arg);        
        System.out.println(c);        
    }

    public int newMethod(boolean arg) {
        int c;
        if (arg) {
            c = 3;
        }
        return c;  // <- variable c might not have been initialized
    }
Comment 1 Jan Becicka 2008-02-14 17:42:59 UTC
Dane, please take a look at it. Thanks.
Comment 2 Jan Becicka 2008-05-15 13:20:56 UTC
Max volunteered :)
Comment 3 Max Sauer 2008-11-24 12:12:40 UTC
Will be resolved LATER.
Comment 4 Jan Lahoda 2009-05-22 14:34:16 UTC
See issue #165780.
Comment 5 Jan Lahoda 2009-05-22 14:35:12 UTC
*** Issue 165780 has been marked as a duplicate of this issue. ***
Comment 6 Jan Lahoda 2010-03-18 21:06:57 UTC
*** Bug 179258 has been marked as a duplicate of this bug. ***
Comment 7 swpalmer 2010-04-20 18:37:10 UTC
It's nearly three years from the initial report.. Has "LATER" become "NOW" yet?
Comment 8 Quality Engineering 2011-04-10 08:41:42 UTC
Integrated into 'main-golden', will be available in build *201104100401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/8bf8d986179b
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #114371: using flow to determine whether the introduce method hint should create a local variable or a parameter.
Comment 9 swpalmer 2011-04-10 13:32:42 UTC
*** Bug 197549 has been marked as a duplicate of this bug. ***
Comment 10 Jan Lahoda 2011-04-11 12:00:56 UTC
*** Bug 196658 has been marked as a duplicate of this bug. ***
Comment 11 Jan Lahoda 2011-04-11 12:07:53 UTC
The above implemented flow should be able to handle the case described in this bug and cases in the duplicates. Possible bugs in the flow implementation should be relatively easy to solve and should be tracked as separate bugs.
Comment 12 ttokoly 2011-04-14 11:44:51 UTC
Product Version: NetBeans IDE Dev (Build 201104140401)
Java: 1.6.0_24; Java HotSpot(TM) Client VM 19.1-b02
System: Linux version 2.6.32-30-generic running on i386; UTF-8; en_US (nb)

Verified, works for me, thanks.