Opening the issue so that the old PR #7631 can be closed (other things that were useful in that PR have been fixed since then; this issue is one thing un-addressed left there).
Triggered by appear to be the keywords. It doesn't look like this really has anything to do with the actual functionality in redetect. The exception appears to be thrown from some innocuous method, like a setting checking. It does not happen on most files. BUT consistently/reproducibly happens on one specific file in prod.:
curl -X POST "http://localhost:8080/api/files/4325124/redetect?key=..."
(and I believe on a few other known files). The above does NOT cause this problem when attempted on a different test server using a copy of the prod. db (!).
We may have seen something similar in other contexts - when checking a setting suddenly causes a problem. This may not be the most pressing issue, but is weird enough to want to figure out what's going on.
See #7631 and #7527 for more info. But the above really describes it. (the only thing I may add later on is an actual stack trace).