History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-17287
Type: Bug Bug
Status: Open Open
Assignee: Bas Leijdekkers
Reporter: Serge Baranov
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

Bug in intention "Manual array to collection copy"

Created: 29 Feb 08 04:24   Updated: 29 Feb 08 12:44
Component/s: Editor. Intention Actions

Build: 7,718
Severity: Medium


 Description  « Hide
Support feedback:

The following code makes intention work incorrect:

import java.util.*;

public class IdeaBug {
    private static Random random = new Random();
    private static final int N = 10;
    public static int nextInt() {
        return random.nextInt(N);
    }

    public static void main(String[] args) {
        List<Integer>[] li = new List[N];
        for (int i = 0; i < N; ++i) {
            li[i] = new ArrayList<Integer>();
        }
        Integer[] values = new Integer[N];
        for (int i = 0; i < N; ++i) {
            values[i] = i;
        }
        //This loop is highlighted.
        for (int i = 1; i < N; ++i) {
            li[nextInt()].add(values[i]);
        }
    }

After applying the intention, remains the following:

import java.util.*;

public class IdeaBug {
    private static Random random = new Random();
    private static final int N = 10;
    public static int nextInt() {
        return random.nextInt(N);
    }

    public static void main(String[] args) {
        List<Integer>[] li = new List[N];
        for (int i = 0; i < N; ++i) {
            li[i] = new ArrayList<Integer>();
        }
        Integer[] values = new Integer[N];
        for (int i = 0; i < N; ++i) {
            values[i] = i;
        }
        li[nextInt()].addAll(Arrays.asList(values).subList(1, N));
    }

which is evidently not the same.

Probably, IDEA thinks that li[nextInt()] is always the same collection.



 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.