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 241120 - Too many return values.
Summary: Too many return values.
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Windows XP
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-29 13:46 UTC by kimsp
Modified: 2014-02-14 02:55 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (102.96 KB, text/plain)
2014-01-29 13:46 UTC, kimsp
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kimsp 2014-01-29 13:46:24 UTC
Product Version = NetBeans IDE Dev (Build 201401290001)
Operating System = Windows XP version 5.1 running on x86
Java; VM; Vendor = 1.7.0_45
Runtime = Java HotSpot(TM) Client VM 24.45-b08

I have this code in a method in a class (using Google Guava):

List<SomeObject> objects = .... ;

       Iterable<String> strings = Iterables.transform(objects, new Function<SomeObject, String>() {
            @Override
            public String apply(SomeObject f) {
                return f.getAString();
            }
        });

I want do extract it to its own method. However, Netbeans tells me that there is "Too many return values.".

The method it should make should look like this:

   private   Iterable<String> getEnvelopeIds(List<SomeObject> objects)  {
           Iterable<String> strings = Iterables.transform(objects, new Function<SomeObject, String>() {
            @Override
            public String apply(SomeObject f) {
                return f.getAString();
            }
        });
    }
Comment 1 kimsp 2014-01-29 13:46:30 UTC
Created attachment 144540 [details]
IDE log
Comment 2 Svata Dedic 2014-01-31 18:45:44 UTC
Please give a complete sample. When I created a testcase using the provided code, everything worked OK.

public abstract class ClassA {
    public void test() {
        List<ClassA> objects = new ArrayList<>();

       Iterable<String> strings = Iterables.transform(objects, new Function<ClassA, String>() {
            @Override
            public String apply(ClassA f) {
                return f.toString();
            }
        });
    }
}


... selected whole lines from "Iterable<String>" to "});" inclusive, Alt-enter, Introduce method.

The message may indicate that your code modifies some local variable whose value is used later in the original function.
Comment 3 kimsp 2014-02-03 11:27:56 UTC
Hi Svata

In your example try to include this line 
System.err.println(strings);

after the:
});

That is, you print out the contents of strings.

Then you cannot select the lines you say without getting a Too Many return values.

I have example code here:

// all below is inside an existing method 

List<String> objects = new ArrayList<String>();

Iterable<String> strings = Iterables.transform(objects, new Function<String, String>() {

   @Override
   public String apply(String f) {
      return f.toString();
   }
});

//Above code I can't refactor if I have this system err commented in.
System.err.println(strings);

List<String> stringsTwo = new ArrayList<String>();
stringsTwo.add("a");
stringsTwo.add("b");
stringsTwo.add("c");

//The above lines (stringsTwo declaration + insertions) I can refactor to a method. Even though I have this system err commented in. 
System.err.println(stringsTwo);
Comment 4 Svata Dedic 2014-02-03 16:01:09 UTC
Great; return was counted as an exit point from the method although it was actually a return from a nested class. The same issue would happen for returns from lambda code blocks or break-continue in nested classes/lambdas.

Fixed in jet-main#9e2ea831f168
Comment 5 Quality Engineering 2014-02-14 02:55:44 UTC
Integrated into 'main-silver', will be available in build *201402140001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/9e2ea831f168
User: Svata Dedic <sdedic@netbeans.org>
Log: #241120: do not count exit points of nested classes and lambdas