Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9050725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:43:37+00:00 2026-06-16T12:43:37+00:00

For some reason, my program suddenly throws a NegativeArraySizeException after running for a while.

  • 0

For some reason, my program suddenly throws a NegativeArraySizeException after running for a while. The code that throws it is behind a command, which I’ve entered before the exception is thrown.

The code I’m using is mostly for debug purposes, and is the following:

final HashMap<String, Integer> busy = new HashMap<>();
//this map gets filled and emptied in threads

System.out.println("Busy tables: " + Arrays.toString(this.busy.keySet().toArray()));
System.out.println("Time busy: " + Arrays.toString(this.busy.values().toArray()));
//map gets read (from the input handler thread)

The exception is thrown on the first System.out.println() line, but I can imagine it being thrown on the other one too if it’d continued running.

Could it be some sort of Threading issue or could the cause be somewhere else?

Google gave me (for the first time in ages) no usable results. How can a Set have a negative size anyway?

Edit: The exception:

Exception in thread "Thread-1" java.lang.NegativeArraySizeException
    at java.util.AbstractCollection.toArray(Unknown Source)
    at nl.lolmewn.statsglobal.Main.handleInput(Main.java:61)
    at nl.lolmewn.statsglobal.Main.access$000(Main.java:20)
    at nl.lolmewn.statsglobal.Main$1.run(Main.java:200)
    at java.lang.Thread.run(Unknown Source)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T12:43:38+00:00Added an answer on June 16, 2026 at 12:43 pm

    Without more information about your code, I would consider unprotected multi-threaded accesses to the HashMap object to be the prime suspect. HashMap, contrary to Hashtable, is not synchronized and needs explicit locks to work in a multi-threaded environment, either directly or through the sets returned via keySet() or entrySet().

    Failing to do that can create a lot of interesting side-effects due to the HashMap being in a inconsistent internal state. I would suggest using a debugger to break on that exception and have a better look at what is going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason this program is saying that 'switch' is not defined. What is
For some reason, my program is skipping the code fragments cin.get(); and cin.ignore(); .
I have a parrallelized C++ program that does brute force optimization. For some reason
For some reason I'm having trouble getting my program to run a while loop.
For some reason when I run the following code the program prints out JDN4
for some reason when running a program it refuses to enter a for loop,
For some reason there is a pause after the program below starts. I believe
For some reason, I can't understand the logic of a program that: Takes in
I have below this program and for some reason that I can't find my
for some reason my server that uses socket.io is not working properly. The program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.