Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while iteration on map values after removal #3

Closed
JanWichniarek opened this issue Apr 28, 2020 · 2 comments
Closed

Error while iteration on map values after removal #3

JanWichniarek opened this issue Apr 28, 2020 · 2 comments
Assignees

Comments

@JanWichniarek
Copy link

Hi,
I experienced strange behaviour of OHMap after removal of element. Here is sample code to generate issue:

    String KEY = "KEY";
    String VALUE = "VALUE";
    OHMap<String, String> ohMap = new OHMap<>(10);
    ohMap.put(KEY, VALUE);
    ohMap.remove(KEY);
    Iterator<String> iterator = ohMap.values().iterator();
    if (iterator.hasNext()) {
        iterator.next();
    }

It generates JVM crash:

# 
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f2a1f9c9aed, pid=25433, tid=0x00007f2a1e608700
#
# JRE version: OpenJDK Runtime Environment (8.0_242-b08) (build 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08)
# Java VM: OpenJDK 64-Bit Server VM (25.242-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0xa81aed]

or Exception:

java.lang.NegativeArraySizeException
	at com.cfelde.bohmap.BOHMap$ValuesIterator.next(BOHMap.java:1009)
	at com.cfelde.bohmap.BOHMap$ValuesIterator.next(BOHMap.java:944)
	at com.cfelde.bohmap.OHMap$Values$1.next(OHMap.java:282)
	at com.cfelde.bohmap.OHMap$Values$1.next(OHMap.java:274)

It looks like iterator#hasNext return true, but Iterator#next causes exception/crash.

@cfelde
Copy link
Owner

cfelde commented Apr 29, 2020

Thanks for the test case, can confirm I see the issue when running it.

I'll look at figuring out what's going wrong and find a fix, hopefully during next week.

@cfelde
Copy link
Owner

cfelde commented Apr 29, 2020

Got around to it early, committed fix

@cfelde cfelde closed this as completed Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants