Bug 538774

Summary: Cannot cast to Iterator<Map.Entry<?,?>>
Product: [Eclipse Project] JDT Reporter: Christoph Langer <christoph.langer>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: 4.9   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard: stalebug

Description Christoph Langer CLA 2018-09-07 05:06:27 EDT
Consider the following code snippet:

Object o = null;
Map<?,?> m = (Map<?,?>)o;
Iterator<Map.Entry<?,?>> it = (Iterator<Map.Entry<?,?>>)m.entrySet().iterator();

This cast does fail in the Eclipse Java compiler with the error:
Cannot cast from Iterator<Map.Entry<capture#3-of ?,capture#4-of ?>> to Iterator<Map.Entry<?,?>>

You'll find this construct in "real life" in java.util.concurrent.ConcurrentSkipListMap.java of OpenJDK:

http://hg.openjdk.java.net/jdk/jdk/file/7e6b86eb7914/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java#l1716

I guess this is a bug!?

I tested with a current master build of the Eclipse platform and the problem still happens.
Comment 1 Eclipse Genie CLA 2020-09-08 01:32:48 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Eclipse Genie CLA 2022-09-01 15:25:37 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.