Skip to content

Commit

Permalink
fix #52, added testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedigerMoeller committed Feb 1, 2015
1 parent f974721 commit 6ccb6cf
Show file tree
Hide file tree
Showing 10 changed files with 1,052 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.ruedigermoeller</groupId>
<artifactId>fst</artifactId>
<version>2.19</version>
<version>2.20</version>

<description>a fast java serialization drop in-replacement + some serialization based utils (Structs, OffHeap Memory)</description>
<url>https://code.google.com/p/fast-serialization/</url>
Expand Down Expand Up @@ -120,7 +120,14 @@
<version>2.1</version>
</dependency>

<!-- test dependencies -->
<!-- test dependencies -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.51</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.cedarsoftware</groupId>
<artifactId>java-util</artifactId>
Expand All @@ -134,11 +141,6 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.1</version>
</dependency>

</dependencies>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/nustaq/serialization/FSTDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ public interface FSTDecoder {
boolean isEndMarker(String s);

int readVersionTag() throws IOException;
void pushBack(int bytes);
}
24 changes: 24 additions & 0 deletions src/main/java/org/nustaq/serialization/FSTObjectInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.nustaq.serialization.util.FSTUtil;
import java.io.*;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
Expand Down Expand Up @@ -920,6 +921,25 @@ ObjectInputStream getObjectInputStream(final Class cl, final FSTClazzInfo clInfo
@Override
public Object readObjectOverride() throws IOException, ClassNotFoundException {
try {
byte b = FSTObjectInput.this.readByte();
if ( b != FSTObjectOutput.SPECIAL_COMPATIBILITY_OBJECT_TAG ) {
Constructor<?>[] constructors = OptionalDataException.class.getDeclaredConstructors();
FSTObjectInput.this.pushBack(1);
for (int i = 0; i < constructors.length; i++) {
Constructor constructor = constructors[i];
if (constructor.getParameterCount() == 1 && constructor.getParameterTypes()[0] == int.class) {
constructor.setAccessible(true);
OptionalDataException ode;
try {
ode = (OptionalDataException) constructor.newInstance(0);
throw ode;
} catch (InvocationTargetException e) {
break;
}
}
}
throw new EOFException("if your code relies on this, think");
}
return FSTObjectInput.this.readObjectInternal(referencee.getPossibleClasses());
} catch (IllegalAccessException e) {
throw new IOException(e);
Expand Down Expand Up @@ -1198,6 +1218,10 @@ public boolean markSupported() {
return fakeWrapper;
}

protected void pushBack(int i) {
getCodec().pushBack(i);
}

static class MyObjectStream extends ObjectInputStream {

ObjectInputStream wrapped;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/nustaq/serialization/FSTObjectOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
public class FSTObjectOutput implements ObjectOutput {

public static final byte SPECIAL_COMPATIBILITY_OBJECT_TAG = -19; // see issue 52
public static final byte ONE_OF = -18;
public static final byte BIG_BOOLEAN_FALSE = -17;
public static final byte BIG_BOOLEAN_TRUE = -16;
Expand Down Expand Up @@ -855,6 +856,7 @@ public void useProtocolVersion(int version) throws IOException {

@Override
protected void writeObjectOverride(Object obj) throws IOException {
getCodec().writeFByte( SPECIAL_COMPATIBILITY_OBJECT_TAG );
FSTObjectOutput.this.writeObjectInternal(obj, null, referencee.getPossibleClasses());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,9 @@ public int readVersionTag() throws IOException {
return readFByte();
}

@Override
public void pushBack(int bytes) {
pos -= bytes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,9 @@ public int readVersionTag() throws IOException {
return 0; // versioning not supported for minbin
}

@Override
public void pushBack(int bytes) {
input.setPos(input.getPos()-bytes);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ public int readVersionTag() throws IOException {
return readFByte();
}

@Override
public void pushBack(int bytes) {
input.pos -= bytes;
}


}

4 changes: 4 additions & 0 deletions src/main/java/org/nustaq/serialization/minbin/MBIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public int getPos() {
return pos;
}

public void setPos(int newpos) {
pos = newpos;
}

public void setBuffer(byte[] buf, int count) {
this.bytez = buf;
pos = 0;
Expand Down
Loading

0 comments on commit 6ccb6cf

Please sign in to comment.