Bug 102599 - [1.5][compiler] Cast error where there is none (Properties->Map)
Summary: [1.5][compiler] Cast error where there is none (Properties->Map)
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-03 17:31 EDT by Claudio Nieder CLA
Modified: 2005-07-04 03:13 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claudio Nieder CLA 2005-07-03 17:31:04 EDT
The following java class can be compiled by Sun's javac 1.5.0_04, yet Eclipse
reports an error saying: Cannot cast from Properties to Map<String,String>

import java.util.Map;

public class Test
{
 public static void main(String[] args)
 {
  Map<String,String> m=(Map<String, String>)System.getProperties();
 }
}
Comment 1 Philipe Mulet CLA 2005-07-04 03:09:16 EDT
Given Properties extends Hashtable<Object,Object>,
the cast comes down to converting Map<Object,Object> to Map<String,String> which
is forbidden by the spec since these are provably distinct types.

Comment 2 Philipe Mulet CLA 2005-07-04 03:13:08 EDT
Note that javac correctly rejects:
import java.util.*;

public class X {
	public void foo(Hashtable<Object,Object> moo) {
		Map<String, String> m = (Map<String, String>) moo;
	}
}

but misses the indirect case when using Properties.
Closing as javac bug.