apache/uima-uimaj

NPE while deserializing an XMI in a PEAR context

benisantos opened this issue · 4 comments

Description
When running an AAE in a PEAR context (uimaj-core 3.3.1), if a CAS Multiplier tries to populate a new CAS while loading it from an XMI file, a NullPointerException is thrown by the method maybeMakeBaseVersionForPear of the class CASImpl.java (line 1536).

To Reproduce
Complete failing example here: https://github.com/benisantos/uima3-xmi-deserializer-in-pear

Workaround
Use the uimaj-io-json library and de/serialize JSON instead of XMI.

Environment

  • SO: macOS 12.6.2
  • OpenJDK Temurin 1.8.0_322
  • uimaj-core 3.3.1

Ok, so it appears that this is what happens:

  • JCas is put into switched-classloader-mode (i.e. PEAR mode) as the PEAR starts processing it
  • the XmiCasDeserializer resets the CAS (using casBeingFilled.resetNoQuestions()) which forces the sets the FS<->trampoline maps in the CAS back to null
  • Later when an FS is created, it sees that the switched-classloader-mode is still active and tries to use the FS<->trampoline maps (that should be present in this mode), but crashes betcause they were set to null

It seems as if UIMA doesn't particular endorse resetting a CAS while in a PEAR context - and this is what the XmiCasDeserializerHandler does when it loads data. However, I think I have a fix that's just a very minimal change - let's see if all the tests run through. At least the manual test case you had provided seems to work with my fix.

@benisantos btw if you want to clone a CAS, there are more efficient ways than saving it to and XMI file and loading it back. E.g. you could use the CasCopier class or you could use the CasIoUtils to serialize the CAS to a byte buffer - check which SerialFormat works most efficiently for you.

@reckart thank you for the quickness :) Our goal is not to clone the CAS (we are processing long texts in big pipelines and we are trying to temporarily save "sub-CASes" to disk in order to reduce memory consumption). Thanks anyway by the advice!