Using threads (and not using a "singleton" shared mime-util instance) the result is, that the Detector classes are not thread-safe at all - it seems its not possible to have more than "one" instance of a detector at different mime util instances because register/deregister does result in this failure:
java.util.ConcurrentModificationException: null
at java.util.Hashtable$Enumerator.next(Hashtable.java:1048) ~[na:1.6.0_20]
at eu.medsea.mimeutil.detector.ExtensionMimeDetector.initMimeTypes(ExtensionMimeDetector.java:291) ~[mime-util-2.1.3.jar:na]
at eu.medsea.mimeutil.detector.ExtensionMimeDetector.<init>(ExtensionMimeDetector.java:104) ~[mime-util-2.1.3.jar:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_20]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.6.0_20]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_20]
at java.lang.reflect.Constructor.newInstance(Constructor.java:532) ~[na:1.6.0_20]
at java.lang.Class.newInstance0(Class.java:372) ~[na:1.6.0_20]
at java.lang.Class.newInstance(Class.java:325) ~[na:1.6.0_20]
at eu.medsea.mimeutil.MimeDetectorRegistry.registerMimeDetector(MimeUtil2.java:967) ~[mime-util-2.1.3.jar:na]
at eu.medsea.mimeutil.MimeUtil2.registerMimeDetector(MimeUtil2.java:222) [mime-util-2.1.3.jar:na]
Don't know the best solution yet - but what i expect is, that different instances does not interfere with each other - but actually this is whats happening - and if they share some code, this code should be thread-safe and should not result in "wrong" results compared to single threaded usage.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Add a synchronized block to the initMimeTypes method should do it. This may slow it down a little, but such problems as discribed will be gone.
Last edit: Anonymous 2014-12-09