修复ArrayEncoder并发下componentEncoder偶尔为null的bug

This commit is contained in:
Redkale
2023-01-04 16:38:20 +08:00
parent 809b574f12
commit 9be0afacef
3 changed files with 23 additions and 9 deletions

View File

@@ -48,6 +48,9 @@ public class ArrayEncoder<T> implements Encodeable<Writer, T[]> {
} }
factory.register(type, this); factory.register(type, this);
this.componentEncoder = factory.loadEncoder(this.componentType); this.componentEncoder = factory.loadEncoder(this.componentType);
if (componentEncoder == null) {
throw new ConvertException("ArrayEncoder init componentEncoder error, componentType = " + this.componentType);
}
this.anyEncoder = factory.getAnyEncoder(); this.anyEncoder = factory.getAnyEncoder();
this.subTypeFinal = (this.componentType instanceof Class) && Modifier.isFinal(((Class) this.componentType).getModifiers()); this.subTypeFinal = (this.componentType instanceof Class) && Modifier.isFinal(((Class) this.componentType).getModifiers());
} finally { } finally {
@@ -84,13 +87,16 @@ public class ArrayEncoder<T> implements Encodeable<Writer, T[]> {
e.printStackTrace(); e.printStackTrace();
} }
} }
itemEncoder = this.componentEncoder;
} }
} }
if (subTypeFinal) { if (subTypeFinal) {
if (out.writeArrayB(value.length, this, itemEncoder, value) < 0) { if (out.writeArrayB(value.length, this, itemEncoder, value) < 0) {
for (int i = 0;; i++) { for (int i = 0;; i++) {
writeMemberValue(out, member, itemEncoder, value[i], i); writeMemberValue(out, member, itemEncoder, value[i], i);
if (i == iMax) break; if (i == iMax) {
break;
}
out.writeArrayMark(); out.writeArrayMark();
} }
} }
@@ -100,7 +106,9 @@ public class ArrayEncoder<T> implements Encodeable<Writer, T[]> {
for (int i = 0;; i++) { for (int i = 0;; i++) {
Object v = value[i]; Object v = value[i];
writeMemberValue(out, member, ((v != null && (v.getClass() == comp || out.specify() == comp)) ? itemEncoder : anyEncoder), v, i); writeMemberValue(out, member, ((v != null && (v.getClass() == comp || out.specify() == comp)) ? itemEncoder : anyEncoder), v, i);
if (i == iMax) break; if (i == iMax) {
break;
}
out.writeArrayMark(); out.writeArrayMark();
} }
} }

View File

@@ -5,14 +5,13 @@
*/ */
package org.redkale.net.http; package org.redkale.net.http;
import org.redkale.annotation.ConstructorParameters;
import org.redkale.asm.MethodDebugVisitor;
import java.nio.channels.CompletionHandler; import java.nio.channels.CompletionHandler;
import java.security.*; import java.security.SecureRandom;
import java.util.concurrent.*; import java.util.concurrent.ConcurrentHashMap;
import org.redkale.asm.*; import org.redkale.annotation.ConstructorParameters;
import static org.redkale.asm.Opcodes.*; import static org.redkale.asm.Opcodes.*;
import org.redkale.net.*; import org.redkale.asm.*;
import org.redkale.net.Context;
import org.redkale.util.*; import org.redkale.util.*;
/** /**
@@ -39,6 +38,7 @@ public class HttpContext extends Context {
protected final AnyValue rpcAuthenticatorConfig; protected final AnyValue rpcAuthenticatorConfig;
//所有Servlet方法都不需要读取http-headerlazyHeaders=true
protected boolean lazyHeaders; //存在动态改值 protected boolean lazyHeaders; //存在动态改值
// protected RequestURINode[] uriCacheNodes; // protected RequestURINode[] uriCacheNodes;

View File

@@ -59,9 +59,15 @@ public final class ByteArray implements ByteTuple {
*/ */
public OutputStream newOutputStream() { public OutputStream newOutputStream() {
return new OutputStream() { return new OutputStream() {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
ByteArray.this.put((byte) b); put((byte) b);
}
@Override
public void write(byte b[], int off, int len) throws IOException {
put(b, off, len);
} }
}; };
} }