Skip to content
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

Sofaboot 4.0 support #96

Merged
merged 46 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d2a265a
feat: atomic
Mar 30, 2023
d0054ba
feat: ignore failure when set accessible
Mar 30, 2023
dc26a38
feat: replace reflection with specific get set for atomic-s
Apr 4, 2023
8896324
Merge branch 'adapater_atomic_v2' into feat_adapt_jdk17
Apr 4, 2023
0d2b9f8
fix: remove handle
Apr 7, 2023
0b85531
Merge branch 'adapater_atomic_v2' into feat_adapt_jdk17
Apr 7, 2023
f820115
fix: log level
Apr 10, 2023
bd30793
Merge branch 'feat_reflect' into feat_adapt_jdk17
Apr 10, 2023
d5bc413
feat: stack trace serialize without reflect
Apr 10, 2023
979a52b
add test case for stack trace
Apr 10, 2023
0ad2bbe
fix: log
Apr 12, 2023
2902e4c
feat: throw v1
Apr 11, 2023
887d0bc
feat: throwable
May 5, 2023
85803a5
merge throwable adapter
May 6, 2023
3dcb68b
format
May 6, 2023
2189859
Merge branch 'adapter_throwable' into feat_adapt_jdk17
May 6, 2023
f2b04c1
format
May 8, 2023
a78fbbb
chore: cr fix
May 23, 2023
448d5c8
Merge branch '3.x' into feat_adapt_jdk17
Jun 8, 2023
8531333
chore: format
Jun 8, 2023
84ac462
add ci fo jdk17
Jun 13, 2023
dd4acab
update jdk
Jun 13, 2023
3811a8a
remove version specific
Jun 13, 2023
d8d3930
Merge branch '3.x' into feat_adapt_jdk17
Jun 19, 2023
5199a3d
version
Jun 19, 2023
8c7e066
chore: add ci on sofaboot-4.0-support
Jun 19, 2023
e36303c
3.5.0.beta.1 release
Jun 20, 2023
84590d1
merge latest
Jun 20, 2023
37767c7
remove aci on sofaboot-4.0-support
Aug 8, 2023
4165eab
Merge remote-tracking branch 'sofaorigin/sofaboot-4.0-support' into s…
Aug 8, 2023
8460cff
feat: add support on java util currency
Aug 9, 2023
fa7ce54
format
Aug 9, 2023
845b01a
init 3.5 snapshot
Aug 9, 2023
4d60e80
merge sofaboot 4.0
Aug 9, 2023
dca0d4b
Merge branch 'feat_currency' into dev/3.5
Aug 9, 2023
ff04ffa
optimized code (#94)
EvenLjj Aug 9, 2023
8da5a9e
Merge branch '3.x' into dev/3.5
Aug 9, 2023
48b9936
format
Aug 10, 2023
dee4e8b
fix: ref problem on currency
Aug 11, 2023
139667a
format
Aug 11, 2023
282ec53
fix: ref bug on atomic
Aug 14, 2023
88b3508
Merge branch '3.x' into sofaboot-4.0-support
Aug 14, 2023
2b9fd8b
version snapshot
Aug 14, 2023
b6d4f13
enhance: ref
Aug 14, 2023
8d02768
fix: test
Aug 14, 2023
ad6153f
Merge branch 'feat_currency' into sofaboot-4.0-support
Aug 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: build

on:
push:
branches: [ master, 3.x,sofaboot-4.0-support ]
branches: [ master, 3.x ]
pull_request:
branches: [ master, 3.x, sofaboot-4.0-support ]
branches: [ master, 3.x ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.alipay.sofa</groupId>
<artifactId>hessian</artifactId>
<version>3.5.0-beta1</version>
<version>3.5.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/caucho/hessian/io/Hessian2Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -3391,7 +3391,7 @@ protected IOException expect(String expect, int ch)
if (obj != null) {
return error("expected " + expect
+ " at 0x" + Integer.toHexString(ch & 0xff)
+ " " + obj.getClass().getName() + " (" + obj + ")");
+ " " + obj.getClass().getName());
}
else
return error("expected " + expect
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/caucho/hessian/io/JavaDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ else if (e instanceof IOException)
throw new HessianFieldException(fieldName + ": " + e.getMessage(), e);

if (value != null)
throw new HessianFieldException(fieldName + ": " + value.getClass().getName() + " (" + value + ")"
throw new HessianFieldException(fieldName + ": " + value.getClass().getName()
+ " cannot be assigned to " + field.getType().getName());
else
throw new HessianFieldException(fieldName + ": " + field.getType().getName() +
Expand Down
38 changes: 28 additions & 10 deletions src/main/java/com/caucho/hessian/io/atomic/AtomicDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import com.caucho.hessian.io.AbstractDeserializer;
import com.caucho.hessian.io.AbstractHessianInput;
import com.caucho.hessian.io.ArrayDeserializer;
import com.caucho.hessian.io.BasicDeserializer;

import java.io.IOException;
Expand All @@ -27,9 +26,8 @@ public class AtomicDeserializer extends AbstractDeserializer {

private Class<?> _type;

private BasicDeserializer intArrayDsr = new BasicDeserializer(BasicDeserializer.INTEGER_ARRAY);
private BasicDeserializer longArrayDsr = new BasicDeserializer(BasicDeserializer.LONG_ARRAY);
private BasicDeserializer objectArrayDsr = new BasicDeserializer(BasicDeserializer.OBJECT_ARRAY);
private BasicDeserializer intArrayDsr = new BasicDeserializer(BasicDeserializer.INTEGER_ARRAY);
private BasicDeserializer longArrayDsr = new BasicDeserializer(BasicDeserializer.LONG_ARRAY);

public AtomicDeserializer(Class<?> cl) {
this._type = cl;
Expand All @@ -39,42 +37,62 @@ public AtomicDeserializer(Class<?> cl) {
public Object readObject(AbstractHessianInput in, String[] fieldNames) throws IOException {

if (AtomicInteger.class.equals(_type)) {
return new AtomicInteger(in.readInt());
AtomicInteger tmp = new AtomicInteger();
in.addRef(tmp);
tmp.set(in.readInt());
return tmp;
}
else if (AtomicBoolean.class.equals(_type)) {
return new AtomicBoolean(in.readInt() == 1);
AtomicBoolean tmp = new AtomicBoolean();
in.addRef(tmp);
tmp.set(in.readInt() == 1);
return tmp;
}
else if (AtomicLong.class.equals(_type)) {
return new AtomicLong(in.readLong());
AtomicLong tmp = new AtomicLong();
in.addRef(tmp);
tmp.set(in.readLong());
return tmp;
}
else if (AtomicReference.class.equals(_type)) {
return new AtomicReference(in.readObject());
AtomicReference tmp = new AtomicReference();
in.addRef(tmp);
tmp.set(in.readObject());
return tmp;
}
else if (AtomicIntegerArray.class.equals(_type)) {
AtomicIntegerArray array = null;
int ref = in.addRef(array);
int[] res = (int[]) intArrayDsr.readObject(in);
int len = res.length;
AtomicIntegerArray array = new AtomicIntegerArray(len);
array = new AtomicIntegerArray(len);
for (int i = 0; i < len; i++) {
array.set(i, res[i]);
}
in.setRef(ref, array);
return array;
}
else if (AtomicLongArray.class.equals(_type)) {
AtomicLongArray array = null;
int ref = in.addRef(array);
long[] res = (long[]) longArrayDsr.readObject(in);
int len = res.length;
AtomicLongArray array = new AtomicLongArray(len);
array = new AtomicLongArray(len);
for (int i = 0; i < len; i++) {
array.set(i, res[i]);
}
in.setRef(ref, array);
return array;
}
else if (AtomicReferenceArray.class.equals(_type)) {
int ref = in.addRef(null);
Object[] res = (Object[]) in.readObject((new Object[0]).getClass());
int len = res.length;
AtomicReferenceArray array = new AtomicReferenceArray(len);
for (int i = 0; i < len; i++) {
array.set(i, res[i]);
}
in.setRef(ref, array);
return array;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerArray;
Expand Down Expand Up @@ -98,6 +100,81 @@ public void test_atomicWrapper() throws IOException {
.get(1));
}

@Test
public void test_ref() throws IOException {
List<AtomicWrapper> l = new ArrayList<AtomicWrapper>();

// prepare
AtomicInteger ai = new AtomicInteger(17);
AtomicBoolean ab = new AtomicBoolean(true);
AtomicLong al = new AtomicLong(2147483649L);
AtomicReference at = new AtomicReference(new Integer(1));
AtomicIntegerArray aia = new AtomicIntegerArray(2);
aia.set(0, 0);
aia.set(1, 1);
AtomicLongArray ala = new AtomicLongArray(2);
ala.set(0, 0L);
ala.set(1, 1L);
AtomicReferenceArray ara = new AtomicReferenceArray(2);
ara.set(0, new Integer(1));
ara.set(1, new Integer(2));

AtomicWrapper atomicWrapper1 = new AtomicWrapper();
atomicWrapper1.setaInteger(ai);
atomicWrapper1.setaBoolean(ab);
atomicWrapper1.setaLong(al);
atomicWrapper1.setaReference(at);
atomicWrapper1.setaIntegerArray(aia);
atomicWrapper1.setaLongArray(ala);
atomicWrapper1.setaReferenceArray(ara);

AtomicWrapper atomicWrapper2 = new AtomicWrapper();
atomicWrapper2.setaInteger(ai);
atomicWrapper2.setaBoolean(ab);
atomicWrapper2.setaLong(al);
atomicWrapper2.setaReference(at);
atomicWrapper2.setaIntegerArray(aia);
atomicWrapper2.setaLongArray(ala);
atomicWrapper2.setaReferenceArray(ara);
l.add(atomicWrapper1);
l.add(atomicWrapper2);

Object result = doEncodeNDecode(l);
Assert.assertTrue(result instanceof List);
List<AtomicWrapper> resultInstance = (List<AtomicWrapper>) result;

Assert.assertTrue(atomicWrapper1 instanceof AtomicWrapper);
AtomicWrapper actual = atomicWrapper1;
Assert.assertEquals(resultInstance.get(0).getaInteger().get(), actual.getaInteger().get());
Assert.assertEquals(resultInstance.get(0).getaBoolean().get(), actual.getaBoolean().get());
Assert.assertEquals(resultInstance.get(0).getaLong().get(), actual.getaLong().get());
Assert.assertEquals(resultInstance.get(0).getaReference().get(), actual.getaReference().get());

Assert.assertEquals(resultInstance.get(0).getaIntegerArray().get(0), actual.getaIntegerArray().get(0));
Assert.assertEquals(resultInstance.get(0).getaIntegerArray().get(1), actual.getaIntegerArray().get(1));
Assert.assertEquals(resultInstance.get(0).getaLongArray().get(0), actual.getaLongArray().get(0));
Assert.assertEquals(resultInstance.get(0).getaLongArray().get(1), actual.getaLongArray().get(1));
Assert.assertEquals(resultInstance.get(0).getaReferenceArray().get(0), actual.getaReferenceArray()
.get(0));
Assert.assertEquals(resultInstance.get(0).getaReferenceArray().get(1), actual.getaReferenceArray()
.get(1));

Assert.assertEquals(resultInstance.get(1).getaInteger().get(), actual.getaInteger().get());
Assert.assertEquals(resultInstance.get(1).getaBoolean().get(), actual.getaBoolean().get());
Assert.assertEquals(resultInstance.get(1).getaLong().get(), actual.getaLong().get());
Assert.assertEquals(resultInstance.get(1).getaReference().get(), actual.getaReference().get());

Assert.assertEquals(resultInstance.get(1).getaIntegerArray().get(0), actual.getaIntegerArray().get(0));
Assert.assertEquals(resultInstance.get(1).getaIntegerArray().get(1), actual.getaIntegerArray().get(1));
Assert.assertEquals(resultInstance.get(1).getaLongArray().get(0), actual.getaLongArray().get(0));
Assert.assertEquals(resultInstance.get(1).getaLongArray().get(1), actual.getaLongArray().get(1));
Assert.assertEquals(resultInstance.get(1).getaReferenceArray().get(0), actual.getaReferenceArray()
.get(0));
Assert.assertEquals(resultInstance.get(1).getaReferenceArray().get(1), actual.getaReferenceArray()
.get(1));

}

@Test
public void test_atomic_unwrappedInteger() throws IOException {
os.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
import com.caucho.hessian.io.SerializerFactory;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
*
Expand Down Expand Up @@ -58,6 +61,36 @@ public void test_stacktrace() throws IOException {

}

@Test
public void test_ref() throws IOException {
Throwable t = null;
try {
int x = 1 / 0;
} catch (Exception e) {
t = e;
}

ExceptionWrapper w1 = new ExceptionWrapper();
w1.setT(t);

ExceptionWrapper w2 = new ExceptionWrapper();
w2.setT(t);

List<ExceptionWrapper> l = new ArrayList<ExceptionWrapper>();
l.add(w1);
l.add(w2);

Object result = doEncodeNDecode(l);
Assert.assertTrue(result instanceof List);

List<ExceptionWrapper> resultInstance = (List<ExceptionWrapper>) result;

Assert.assertEquals(l.get(0).t.getMessage(), resultInstance.get(0).t.getMessage());
Assert.assertEquals(l.get(0).t.getStackTrace().length, resultInstance.get(0).t.getStackTrace().length);

Assert.assertEquals(l.get(1).t.getMessage(), resultInstance.get(1).t.getMessage());
}

protected Object doEncodeNDecode(Object origin) throws IOException {
os.reset();
Hessian2Output output = new Hessian2Output(os);
Expand Down