You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "Yuriy Koval (JIRA)" <ji...@apache.org> on 2018/06/20 19:36:00 UTC
[jira] [Created] (TIKA-2677) ConcurrentModificationException in
org.apache.tika.mime.MediaTypeRegistry.getAliases
Yuriy Koval created TIKA-2677:
---------------------------------
Summary: ConcurrentModificationException in org.apache.tika.mime.MediaTypeRegistry.getAliases
Key: TIKA-2677
URL: https://issues.apache.org/jira/browse/TIKA-2677
Project: Tika
Issue Type: Bug
Affects Versions: 1.18
Reporter: Yuriy Koval
When using Tika parser on multiple threads and calling MediaTypeRegistry.getAliases, we get ConcurrentModificationException:
{noformat}
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)
at java.util.HashMap$EntryIterator.next(HashMap.java:1463)
at java.util.HashMap$EntryIterator.next(HashMap.java:1461)
at org.apache.tika.mime.MediaTypeRegistry.getAliases(MediaTypeRegistry.java:78){noformat}
It will go away, if we use ConcurrentMap here:
[https://github.com/apache/tika/blob/master/tika-core/src/main/java/org/apache/tika/mime/MediaTypeRegistry.java#L49]
Here is code snippet to recreate the problem:
{code:java}
static boolean stop = false;
public static void main(String[] args) throws MimeTypeException {
MimeTypes mimeTypes = MimeTypes.getDefaultMimeTypes();
Executors.newSingleThreadExecutor().execute(() -> {
try {
for (int i=0; i < 1000 && !stop; i++) {
System.out.println(mimeTypes.forName("abc" + i + "/abc"));
}
} catch (MimeTypeException e) {
e.printStackTrace();
}
});
for (int i=0; i < 1000 && !stop; i++) {
try {
System.out.println(mimeTypes.getMediaTypeRegistry().getAliases(MediaType.APPLICATION_ZIP));
} catch (ConcurrentModificationException ex) {
stop = true;
ex.printStackTrace();
}
}
}{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)