Bug 576404 - Bad type on operand stack when using Map.Entry.getKey() in switch statement when compiled with Java 17
Summary: Bad type on operand stack when using Map.Entry.getKey() in switch statement w...
Status: CLOSED DUPLICATE of bug 576093
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: PC Windows 10
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-02 04:16 EDT by Emanuel Kupcik CLA
Modified: 2021-10-05 05:40 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emanuel Kupcik CLA 2021-10-02 04:16:47 EDT

    
Comment 1 Emanuel Kupcik CLA 2021-10-02 04:19:05 EDT
The following code crashes when compiled with Java 17 plugin

public class Test
{

	public static void main(String[] args)
	{
		Map<String, String> map = new HashMap<>();
		map.put("key1", "value1");
		map.put("key2", "value2");

		for(Iterator<Map.Entry<String, String>> iter = map.entrySet().iterator(); iter.hasNext();)
		{
			Map.Entry<String, String> entry = iter.next();
			switch(entry.getKey())
			{
				case "key1":
					break;
				case "key2":
					break;
			}
		}
	}

}

When you first assign entry.getKey to a local variable and use that one in the switch it works fine
Comment 2 Emanuel Kupcik CLA 2021-10-02 04:20:36 EDT
Ursache: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Test.main([Ljava/lang/String;)V @64: invokevirtual
  Reason:
    Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'java/lang/String'
  Current Frame:
    bci: @64
    flags: { }
    locals: { '[Ljava/lang/String;', 'java/util/Map', 'java/util/Iterator', 'java/util/Map$Entry', 'java/lang/Object' }
    stack: { 'java/lang/Object' }
  Bytecode:
    0000000: bb00 1059 b700 124c 2b12 1312 15b9 0017
    0000010: 0300 572b 121d 121f b900 1703 0057 2bb9
    0000020: 0021 0100 b900 2501 004d a700 492c b900
    0000030: 2b01 00c0 0031 4e2d b900 3301 0059 3a04
    0000040: b600 36ab 0000 0030 0000 0002 0032 2db2
    0000050: 0000 0019 0032 2db3 0000 0026 1904 1213
    0000060: b600 3c9a 0010 a700 0d19 0412 1db6 003c
    0000070: 9a00 032c b900 4001 009a ffb4 b1       
  Stackmap Table:
    append_frame(@45,Object[#24],Object[#44])
    append_frame(@92,Object[#49],Object[#55])
    same_frame(@105)
    chop_frame(@115,2)
Comment 3 Andrey Loskutov CLA 2021-10-02 04:33:53 EDT
I believe this was dixed in recent builds. Could you please try 4.22 M1? https://download.eclipse.org/eclipse/downloads/drops4/S-4.22M1-202109291800/
Comment 4 Andrey Loskutov CLA 2021-10-05 05:40:50 EDT
Works on 4.22 master. I assume duplicate of bug 576093.

*** This bug has been marked as a duplicate of bug 576093 ***