kaiyaok2 commented on PR #1754:
URL: https://github.com/apache/tika/pull/1754#issuecomment-2105675512
> The `repo` is refreshed with each unit test in the `@BeforeEach` call,
though. Is NIODetector respecting that?
@tballison Yes, NIOInspector uses the JUnit Jupiter engine and takes into
account of all setup and teardown methods. Notice that although the `MimeTypes`
instance `repo` is refreshed, `MimeTypes.addPattern()` calls `Patterns.add()`
,which then calls `addGlob()`:
```
private void addGlob(String glob, MimeType type) throws MimeTypeException {
MimeType previous = globs.get(glob);
if (previous == null ||
registry.isSpecializationOf(previous.getType(), type.getType())) {
globs.put(glob, type);
} else if (previous == type ||
registry.isSpecializationOf(type.getType(),
previous.getType())) {
// do nothing
} else {
throw new MimeTypeException("Conflicting glob pattern: " + glob);
}
}
```
In the second execution of the test, `previous` would be the `testType`
object constructed in the first test run, while `type` is the `testType` object
constructed in the second test run (from 2 different calls to `new
MimeType(MediaType.parse("foo/bar"))`. Now since `previous != type` are not the
same, the exception is thrown.
Ideally we shall go to the `// do nothing` branch in repeated runs, thus the
fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]