Bug 102599

Summary: [1.5][compiler] Cast error where there is none (Properties->Map)
Product: [Eclipse Project] JDT Reporter: Claudio Nieder <private>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1.1   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:

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.