-
-
Notifications
You must be signed in to change notification settings - Fork 924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JRuby does not follow ObjectInputStream casting convention #2226
Comments
The cast here (in Java) actually does nothing special other than confirm the object is of type Blah and cause subsequent bytecode to see it as a Blah. The results of calling ObjectInputStream#readObject would be unchanged. Can you show a runnable example that fails? |
I can try. It would require a lot of setup, but I'll try to put together the most slimmed-down version I can. The Java side is extensive, and not mine. (thanks for looking, though) |
This won't be runnable without a bunch of other stuff and a fairly lengthy setup. Perhaps you'll get an idea just by looking at the source (there's a fair chance of dumb rookie errors on my part). I don't know if it's noteworthy or not, but InstanceList does not appear directly as a class in either the serialization or deserialization methods, but it could be embedded in another object (not clear to me from the source whether it might be, but if it is, it's probably in the first ArrayList read by ParallelTopicModel::readObject. JRuby sideclass JCaseTagger
def initialize(tmodel_fn = DEFAULT_TRAINED_MODEL_FN)
myfile = java.io.File.new(tmodel_fn)
@model = Java::CcMalletTopics::ParallelTopicModel::read(myfile)
end
end Java sidepublic static ParallelTopicModel read (File f) throws Exception {
ParallelTopicModel topicModel = null;
ObjectInputStream ois = new ObjectInputStream (new FileInputStream(f));
topicModel = (ParallelTopicModel) ois.readObject();
ois.close();
topicModel.initializeHistograms();
return topicModel;
}
private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {
int version = in.readInt ();
data = (ArrayList<TopicAssignment>) in.readObject ();
alphabet = (Alphabet) in.readObject();
topicAlphabet = (LabelAlphabet) in.readObject();
/* ... many more reads of primitive objects follow, included for completeness*/
numTopics = in.readInt();
topicMask = in.readInt();
topicBits = in.readInt();
numTypes = in.readInt();
alpha = (double[]) in.readObject();
alphaSum = in.readDouble();
beta = in.readDouble();
betaSum = in.readDouble();
typeTopicCounts = (int[][]) in.readObject();
tokensPerTopic = (int[]) in.readObject();
docLengthCounts = (int[]) in.readObject();
topicDocCounts = (int[][]) in.readObject();
numIterations = in.readInt();
burninPeriod = in.readInt();
saveSampleInterval = in.readInt();
optimizeInterval = in.readInt();
showTopicsInterval = in.readInt();
wordsPerTopic = in.readInt();
saveStateInterval = in.readInt();
stateFilename = (String) in.readObject();
saveModelInterval = in.readInt();
modelFilename = (String) in.readObject();
randomSeed = in.readInt();
formatter = (NumberFormat) in.readObject();
printLogLikelihood = in.readBoolean();
numThreads = in.readInt();
} Stack trace from IDE
|
This turned out to be something entirely stupid. Let the ridicule commence. |
(insert not-a-Java-programmer disclaimer here).
This code:
seems to be an idiom; the cast invokes the use of a private Blah.readObject method to pull complex objects off the stream . JRuby, on the other hand, appears to try to cast the first non-primitive object in the stream to type Blah, and can't.
The text was updated successfully, but these errors were encountered: