Bug 184862 - [evaluation] evaluation in static method with generics does not work
Summary: [evaluation] evaluation in static method with generics does not work
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.3   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P2 normal (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Curtis Windatt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 156370 176648 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-05-01 10:25 EDT by Darin Wright CLA
Modified: 2010-10-18 06:22 EDT (History)
5 users (show)

See Also:


Attachments
patch (1.70 KB, patch)
2007-05-03 10:25 EDT, Darin Wright CLA
no flags Details | Diff
improved patch (2.03 KB, patch)
2007-05-03 11:10 EDT, Darin Wright CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Wright CLA 2007-05-01 10:25:41 EDT
I20070501-0010

* Using the following source
* Debug to a breakpoint in deal()
* evaluate "deck.subList(deckSize-n, deckSize)"
> error: Evaluations must contain either an expression or a block of well formed statements 

public class Deal {
    public static void main(String args[]) {
        int numHands = Integer.parseInt(args[0]);
        int cardsPerHand = Integer.parseInt(args[1]);
        List<Card> deck  = Card.newDeck();
        Collections.shuffle(deck);
        for (int i=0; i < numHands; i++)
            System.out.println(deal(deck, cardsPerHand));
    }

    public static ArrayList<Card> deal(List<Card> deck, int n) {
         int deckSize = deck.size();
         List<Card> handView = deck.subList(deckSize-n, deckSize);
         ArrayList<Card> hand = new ArrayList<Card>(handView);
         handView.clear();
         return hand;
     }
}

and

import java.util.*;

public class Card {
    public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX,
        SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }

    public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }

    private final Rank rank;
    private final Suit suit;
    private Card(Rank rank, Suit suit) {
        this.rank = rank;
        this.suit = suit;
    }

    public Rank rank() { return rank; }
    public Suit suit() { return suit; }
    public String toString() { return rank + " of " + suit; }

    private static final List<Card> protoDeck = new ArrayList<Card>();

    // Initialize prototype deck
    static {
        for (Suit suit : Suit.values())
            for (Rank rank : Rank.values())
                protoDeck.add(new Card(rank, suit));
    }

    public static ArrayList<Card> newDeck() {
        return new ArrayList<Card>(protoDeck); // Return copy of prototype deck
    }
}
Comment 1 Darin Wright CLA 2007-05-02 12:31:32 EDT
unable to reproduce on Windows or Mac
Comment 2 Darin Wright CLA 2007-05-03 10:20:35 EDT
Re-opening. Found a case where this dose not work.
Comment 3 Darin Wright CLA 2007-05-03 10:22:06 EDT
In the following example, set a breakpoint on last sysout. Try to eval "list.get(0)" > error. We should only be adding type parameters for wild card types, not parameterized types like <Integer>.

public class Eval {
	public static void main(String[] args) {
		ArrayList<Integer> list = new ArrayList<Integer>();
		list.add(1024);
		int x = 1;
		for (int j = 0; j <= 10; j++) {
			list.add(x);
			x *= 2;
		}
		for (int i : list) {
			System.out.print(i + "\t");
		}
		System.out.println();
		boolean b = list.get(0) != list.get(list.size() - 1);
		// Breakpoint the next line: copy the right side of
		// the previous line (list.get(0) ... ) into the Display
		// view and evaluate it
		System.out.println("Test says " + b);
		// Display tab evaluation yields false; value of b is true

	}
}
Comment 4 Darin Wright CLA 2007-05-03 10:25:11 EDT
Created attachment 65770 [details]
patch
Comment 5 Darin Wright CLA 2007-05-03 11:10:11 EDT
Created attachment 65783 [details]
improved patch

Accounts for types like <T extends Comparable<T>>.
Comment 6 Darin Wright CLA 2007-05-03 11:10:37 EDT
*** Bug 176648 has been marked as a duplicate of this bug. ***
Comment 7 Darin Wright CLA 2007-05-04 10:25:54 EDT
*** Bug 156370 has been marked as a duplicate of this bug. ***
Comment 8 Darin Wright CLA 2007-05-04 14:27:55 EDT
Released to HEAD.
Comment 9 Darin Wright CLA 2007-05-04 14:28:16 EDT
Please verify, Curtis.
Comment 10 Curtis Windatt CLA 2007-05-07 11:04:17 EDT
Verified
Comment 11 Eclipse Webmaster CLA 2007-07-29 09:22:31 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991
Comment 12 Achiya Elyasaf CLA 2009-11-15 01:57:30 EST
I'm using eclipse 3.5.1 for 64bit computers and the fix does not work
Comment 13 Darin Wright CLA 2009-11-15 16:30:33 EST
(In reply to comment #12)
> I'm using eclipse 3.5.1 for 64bit computers and the fix does not work

Please open a new bug with steps to reproduce.
Comment 14 Polina Morozova CLA 2010-09-03 02:04:21 EDT
(In reply to comment #13)
> (In reply to comment #12)
> > I'm using eclipse 3.5.1 for 64bit computers and the fix does not work
> 
> Please open a new bug with steps to reproduce.

I found that this bug for 64bit eclipse's version is not fixed yet, too. 

Eclipse Platform
Version: 3.6.0.v20100602-9gF78GpqFt6trOGhL60z0oEx3fz-JKNwxPY
Build id: I20100608-0911

Windows 7 Enterprise 64-bit

Actually, its difficult to reproduce - some time its working correctly, some time even expressions like 1+1 not evaluated!

Maybe you should fix it by not searching reproducing steps, but another way... its found from 2007 year and not yet fixed for today!...