1
votes

I have a very strange behavior in my application(a vlcj base music player). I use a ConcurrentHashMap to cache information about an artist.

If i call get on the HashMap the program seems to stop, but no exception is thrown. The "a" has been printed out, but the "b" has never been printed out.

In a separate thread i ran a deadlock check but it, no deadlock was detected, and I'm very sure that I don't use the Cache in another thread.

public void newMedia(MediaPlayer mediaPlayer) {
    MusicListItem item = this.playListModel.getActiveItem();

    System.out.println("a");
    // cachedArtists = ConcurrentHashMap<String, Artist>
    Artist artist = this.cachedArtists.get(item.getArtist());
    System.out.println("b");
}

Did i found a JVM-Bug?

Here is my JVM: java version "1.7.0_40" Java(TM) SE Runtime Environment (build 1.7.0_40-b43) Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

3
does it hang after printing a? if yes what does thread dump show when it hangs after printing a ? - jmj
I can tell you right away that you didn't find a JVM bug. - Marko Topolnik
why do you use ConcurrentHashMap if you do not use it in any other thread ? - gregory561
Wrap it in a try catch with a e.printStackTrace() in the catch section. That'll tell you for certain if anything is happening. - christopher
it may happen that you source java file isn't in sync with class file or are you sure program exits? It would be good if you post some more content of your code item.getArtist etc.. - harsh

3 Answers

1
votes

I see three things that could go wrong here, you might want to check whether they can actually happen (I don't have enough context to tell):

  • cachedArtists might be null
  • item might be null (there is not active item in the playListModel)
  • item.getArtist() might error out (exception or System.exit())

Most of these cases involve an exception being thrown so you would expect to see a stacktrace, but maybe this is swallowed somewhere up in the callstack - again, I don't have the context to tell. Best follow Chris's advice to figure out by wrapping the offending line into a try...catch block yourself and print the stack trace of any exception manually.

0
votes

Like Chris said, I put a try catch block arround the code and indeed I got a JavaClassCastEXception:

java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to de.roth.jsona.artist.Artist

0
votes

If the program just hangs (does not terminate), I'd guess that item.getArtist() blocks. Verify via

System.out.println("a");
Artist key = item.getArtist();
System.out.println("b");
Artist artist = this.cachedArtists.get(key);
System.out.println("c");

(getting an artist via an Artist(?) smells of Munchhausen pattern btw)