Skip to content

Java class not found when deserializing with ObjectInputStream #453

@TovlyDeutsch

Description

@TovlyDeutsch

I'm using the Stanford Parser with pyjnius. Using the autoclass function of pyjnius, I can use the java classes from the parser. However, when I try to deserialize something that uses those classes, I get a ClassNotFoundException. How could I ensure that the jvm has access to the the class when deserializing (calling readObject)?

This works fine

ArrayList = autoclass('java.util.ArrayList')
ScoredObject = autoclass('edu.stanford.nlp.util.ScoredObject')
sensTrees = ArrayList()
sensTrees.add(ScoredObject(ArrayList(), 5))
outFile = FileOutputStream('javaParses.ser')
oos = ObjectOutputStream(outFile)
oos.writeObject(sensTrees)

But this throws the error below

inFile = FileInputStream('javaParses.ser')
ois = ObjectInputStream(inFile)
Docs = ois.readObject() // this line throws the error

Error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\we890\seniorThesis\parseDocs.py", line 75, in test
    Docs = ois.readObject()
  File "jnius\jnius_export_class.pxi", line 766, in jnius.JavaMethod.__call__
  File "jnius\jnius_export_class.pxi", line 843, in jnius.JavaMethod.call_method
  File "jnius\jnius_utils.pxi", line 91, in jnius.check_exception
jnius.JavaException: JVM exception occurred: edu.stanford.nlp.util.ScoredObject

Older Error (I think from a different jdk and pyjinius version)

java.lang.ClassNotFoundException: edu.stanford.nlp.util.ScoredObject

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions