I have a fork of a plugin and was trying to fix it, because the same error kept showing up.
Some stack traces look like this:
com.intellij.psi.tree.IElementType$TooManyElementTypesException: Too many element types registered. Out of (short) range. Most of element types (...) were registered for ...
at com.intellij.psi.tree.IElementType$TooManyElementTypesException.create(IElementType.java:351)
at com.intellij.psi.tree.IElementType.lambda$checkSizeDoesNotExceedLimit$2(IElementType.java:296)
at com.intellij.openapi.application.impl.ApplicationImpl$4.run(ApplicationImpl.java:381)
and others look like this:
java.lang.ArrayIndexOutOfBoundsException: Index -32708 out of bounds for length 40457
at com.intellij.psi.tree.IElementType.<init>(IElementType.java:134)
at com.intellij.psi.tree.IElementType.<init>(IElementType.java:111)
at com.intellij.psi.tree.ILazyParseableElementType.<init>(ILazyParseableElementType.java:35)
at com.intellij.psi.tree.IFileElementType.<init>(IFileElementType.java:16)
The first one is very intuitive. It clearly says that too many element types were registered, and that the limit is related to the short range.
The second one is much more counterintuitive. It only shows an ArrayIndexOutOfBoundsException with index -32708, which is very close to the short overflow boundary, but it does not explain the real cause at all.
In my case, the actual plugin bug was repeatedly registering new element types, so the correct fix is of course to stop doing that. But I still think the second case should ideally produce a clear diagnostic like “too many element types registered” instead of a confusing negative array index error.
Is this something that should be improved in the platform, or is there already some reason why this path ends up with a raw ArrayIndexOutOfBoundsException instead?