You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "Tim Allison (JIRA)" <ji...@apache.org> on 2018/06/21 20:16:00 UTC

[jira] [Resolved] (TIKA-2677) ConcurrentModificationException in org.apache.tika.mime.MediaTypeRegistry.getAliases

     [ https://issues.apache.org/jira/browse/TIKA-2677?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Allison resolved TIKA-2677.
-------------------------------
       Resolution: Fixed
         Assignee: Tim Allison
    Fix Version/s: 2.0.0
                   1.19

Thank you [~yuriy-b-koval] for opening this, diagnosing it, fixing it and supplying a test!

> 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
>            Assignee: Tim Allison
>            Priority: Major
>             Fix For: 1.19, 2.0.0
>
>
> 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)