JDK-6302956 : Illegal cast allowed Properties -> Map
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-07-28
  • Updated: 2010-04-02
  • Resolved: 2005-08-04
Related Reports
Duplicate :  
Description
https://bugs.eclipse.org/bugs/show_bug.cgi?id=102599

javac accepts this illegal program:

import java.util.Map;
 
public class Test {
    Object test() {
        return (Map<String, String>)System.getProperties();
    }
}

Comments
EVALUATION A Properties object implements Map<Object,Object> which is not a Map<String,String>. Other compilers already reject this program. The program can be made to compile with a cast like this: (Map)System.getProperties(). This is strongly discouraged as the cast is incorrect and can cause problems later.
26-09-2005