Skip to content
Snippets Groups Projects
Commit c0c5c747 authored by srosse's avatar srosse
Browse files

OO-1226: bypass serialVersionUID from qti.ser, only write a warn if not ok

parent 1d203b5b
No related branches found
No related tags found
No related merge requests found
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.ims.qti.process;
import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
/**
*
* http://stackoverflow.com/questions/795470/how-to-deserialize-an-object-persisted-in-a-db-now-when-the-object-has-different
*
* @author jorge, java forums
*
*/
public class DecompressibleInputStream extends ObjectInputStream {
private static final OLog log = Tracing.createLoggerFor(DecompressibleInputStream.class);
public DecompressibleInputStream(InputStream in) throws IOException {
super(in);
}
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
ObjectStreamClass resultClassDescriptor = super.readClassDescriptor(); // initially streams descriptor
Class<?> localClass = Class.forName(resultClassDescriptor.getName()); // the class in the local JVM that this descriptor represents.
if (localClass == null) {
log.error("No local class for " + resultClassDescriptor.getName());
return resultClassDescriptor;
}
ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
if (localClassDescriptor != null) { // only if class implements serializable
final long localSUID = localClassDescriptor.getSerialVersionUID();
final long streamSUID = resultClassDescriptor.getSerialVersionUID();
if (streamSUID != localSUID) { // check for serialVersionUID mismatch.
final StringBuilder s = new StringBuilder("Overriding serialized class version mismatch: ");
s.append("local serialVersionUID = ").append(localSUID).append(" stream serialVersionUID = ").append(streamSUID);
Exception e = new InvalidClassException(s.toString());
log.warn(s.toString(), e);
resultClassDescriptor = localClassDescriptor;
}
}
return resultClassDescriptor;
}
}
...@@ -156,7 +156,7 @@ public class FilePersister implements Persister { ...@@ -156,7 +156,7 @@ public class FilePersister implements Persister {
} }
is = new FileInputStream(new File(fSerialDir, QTI_FILE)); is = new FileInputStream(new File(fSerialDir, QTI_FILE));
BufferedInputStream bis = new BufferedInputStream(is, 262144); BufferedInputStream bis = new BufferedInputStream(is, 262144);
ObjectInputStream oistream = new ObjectInputStream(bis); ObjectInputStream oistream = new DecompressibleInputStream(bis);
o = oistream.readObject(); o = oistream.readObject();
oistream.close(); oistream.close();
is.close(); is.close();
...@@ -166,6 +166,7 @@ public class FilePersister implements Persister { ...@@ -166,6 +166,7 @@ public class FilePersister implements Persister {
} }
} catch (Exception e) { } catch (Exception e) {
log.error("", e);
try { try {
if (is != null) is.close(); if (is != null) is.close();
} catch (IOException e1) { } catch (IOException e1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment