优化ConvertException

This commit is contained in:
Redkale
2022-12-23 21:15:42 +08:00
parent b656c8877b
commit 8636a1a43d
5 changed files with 20 additions and 23 deletions

View File

@@ -12,11 +12,10 @@ import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.CompletionHandler;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.*;
import java.util.regex.Pattern;
import java.util.stream.*;
import org.redkale.annotation.ConstructorParameters;
import org.redkale.convert.bson.BsonConvert;
import org.redkale.convert.ext.*;
@@ -575,7 +574,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
if (params.length == 0) {
encoder = (Encodeable) constructor.newInstance();
} else if (params.length == 1) {
if (paramTypes[0] != Type.class) throw new RuntimeException(clazz2 + " not found public empty-parameter Constructor");
if (paramTypes[0] != Type.class) throw new ConvertException(clazz2 + " not found public empty-parameter Constructor");
encoder = (Encodeable) constructor.newInstance(colType);
} else if (params.length == 2) {
if (paramTypes[0] == ConvertFactory.class && paramTypes[1] == Type.class) {
@@ -583,10 +582,10 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
} else if (paramTypes[0] == Type.class && paramTypes[1] == ConvertFactory.class) {
encoder = (Encodeable) constructor.newInstance(colType, this);
} else {
throw new RuntimeException(clazz2 + " not found public empty-parameter Constructor");
throw new ConvertException(clazz2 + " not found public empty-parameter Constructor");
}
} else {
throw new RuntimeException(clazz2 + " not found public empty-parameter Constructor");
throw new ConvertException(clazz2 + " not found public empty-parameter Constructor");
}
RedkaleClassLoader.putReflectionPublicConstructors(clazz2, clazz2.getName());
if (encoderList == null) encoderList = new ArrayList<>();
@@ -620,7 +619,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
if (params.length == 0) {
decoder = (Decodeable) constructor.newInstance();
} else if (params.length == 1) {
if (paramTypes[0] != Type.class) throw new RuntimeException(clazz2 + " not found public empty-parameter Constructor");
if (paramTypes[0] != Type.class) throw new ConvertException(clazz2 + " not found public empty-parameter Constructor");
decoder = (Decodeable) constructor.newInstance(colType);
} else if (params.length == 2) {
if (paramTypes[0] == ConvertFactory.class && paramTypes[1] == Type.class) {
@@ -628,10 +627,10 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
} else if (paramTypes[0] == Type.class && paramTypes[1] == ConvertFactory.class) {
decoder = (Decodeable) constructor.newInstance(colType, this);
} else {
throw new RuntimeException(clazz2 + " not found public empty-parameter Constructor");
throw new ConvertException(clazz2 + " not found public empty-parameter Constructor");
}
} else {
throw new RuntimeException(clazz2 + " not found public empty-parameter Constructor");
throw new ConvertException(clazz2 + " not found public empty-parameter Constructor");
}
RedkaleClassLoader.putReflectionPublicConstructors(clazz2, clazz2.getName());
if (decoderList == null) decoderList = new ArrayList<>();
@@ -866,7 +865,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
try {
clazz.getDeclaredField(field);
} catch (Exception e) {
throw new RuntimeException(clazz + " not found field(" + field + ")");
throw new ConvertException(clazz + " not found field(" + field + ")");
}
if (coder == null) {
Map map = this.fieldCoders.get(clazz);

View File

@@ -6,11 +6,10 @@
package org.redkale.convert;
import java.lang.reflect.*;
import org.redkale.annotation.Comment;
import org.redkale.persistence.Column;
import org.redkale.source.FilterColumn;
import org.redkale.util.*;
import org.redkale.util.Attribute;
/**
* 字段的反序列化操作类
@@ -95,7 +94,7 @@ public final class DeMember<R extends Reader, T, F> {
Field field = clazz.getDeclaredField(fieldName);
return new DeMember<>(Attribute.create(field), factory.loadDecoder(field.getGenericType()), field, null);
} catch (Exception e) {
throw new RuntimeException(e);
throw new ConvertException(e);
}
}
@@ -104,7 +103,7 @@ public final class DeMember<R extends Reader, T, F> {
Field field = clazz.getDeclaredField(fieldName);
return new DeMember<>(Attribute.create(clazz, fieldName, fieldType), factory.loadDecoder(fieldType), field, null);
} catch (Exception e) {
throw new RuntimeException(e);
throw new ConvertException(e);
}
}
@@ -160,7 +159,7 @@ public final class DeMember<R extends Reader, T, F> {
if (o == null) return -1;
if (this.position != o.position) return (this.position == 0 ? Integer.MAX_VALUE : this.position) - (o.position == 0 ? Integer.MAX_VALUE : o.position);
if (this.index != o.index) return (this.index == 0 ? Integer.MAX_VALUE : this.index) - (o.index == 0 ? Integer.MAX_VALUE : o.index);
if (this.index != 0) throw new RuntimeException("fields (" + attribute.field() + ", " + o.attribute.field() + ") have same ConvertColumn.index(" + this.index + ") in " + attribute.declaringClass());
if (this.index != 0) throw new ConvertException("fields (" + attribute.field() + ", " + o.attribute.field() + ") have same ConvertColumn.index(" + this.index + ") in " + attribute.declaringClass());
return fieldSort ? this.attribute.field().compareTo(o.attribute.field()) : 0;
}

View File

@@ -6,11 +6,10 @@
package org.redkale.convert;
import java.lang.reflect.*;
import org.redkale.annotation.Comment;
import org.redkale.persistence.Column;
import org.redkale.source.FilterColumn;
import org.redkale.util.*;
import org.redkale.util.Attribute;
/**
* 字段的序列化操作类
@@ -106,7 +105,7 @@ public final class EnMember<W extends Writer, T, F> {
Field field = clazz.getDeclaredField(fieldname);
return new EnMember<>(Attribute.create(field), factory.loadEncoder(field.getGenericType()), field, null);
} catch (Exception e) {
throw new RuntimeException(e);
throw new ConvertException(e);
}
}
@@ -115,7 +114,7 @@ public final class EnMember<W extends Writer, T, F> {
Field field = clazz.getDeclaredField(fieldname);
return new EnMember<>(Attribute.create(clazz, fieldname, fieldtype), factory.loadEncoder(fieldtype), field, null);
} catch (Exception e) {
throw new RuntimeException(e);
throw new ConvertException(e);
}
}
@@ -179,7 +178,7 @@ public final class EnMember<W extends Writer, T, F> {
if (o == null) return -1;
if (this.position != o.position) return (this.position == 0 ? Integer.MAX_VALUE : this.position) - (o.position == 0 ? Integer.MAX_VALUE : o.position);
if (this.index != o.index) return (this.index == 0 ? Integer.MAX_VALUE : this.index) - (o.index == 0 ? Integer.MAX_VALUE : o.index);
if (this.index != 0) throw new RuntimeException("fields (" + attribute.field() + ", " + o.attribute.field() + ") have same ConvertColumn.index(" + this.index + ") in " + attribute.declaringClass());
if (this.index != 0) throw new ConvertException("fields (" + attribute.field() + ", " + o.attribute.field() + ") have same ConvertColumn.index(" + this.index + ") in " + attribute.declaringClass());
return fieldSort ? this.attribute.field().compareTo(o.attribute.field()) : 0;
}

View File

@@ -8,8 +8,8 @@ package org.redkale.convert.json;
import java.lang.reflect.*;
import java.lang.reflect.Type;
import java.util.*;
import org.redkale.asm.*;
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
import org.redkale.asm.*;
import static org.redkale.asm.Opcodes.*;
import org.redkale.convert.*;
import org.redkale.convert.ext.*;
@@ -705,7 +705,7 @@ public abstract class JsonDynEncoder<T> implements Encodeable<JsonWriter, T> {
}
return resultEncoder;
} catch (Exception ex) {
throw new RuntimeException(ex);
throw new ConvertException(ex);
}
}

View File

@@ -5,7 +5,7 @@ package org.redkale.convert.json;
import java.lang.reflect.Type;
import java.util.*;
import org.redkale.convert.*;
import org.redkale.util.*;
import org.redkale.util.Attribute;
/**
* 抽象或接口类存在多种实现类的反序列化解析器 <br>
@@ -56,7 +56,7 @@ public class JsonMultiImplDecoder<T> implements Decodeable<JsonReader, T> {
if (t == null) {
fieldTypes.put(name, member.getAttribute());
} else if (!member.getAttribute().genericType().equals(t.genericType())) {
throw new RuntimeException("Field(" + name + ")'s Type is not same in " + member.getAttribute().declaringClass() + " and " + t.declaringClass());
throw new ConvertException("Field(" + name + ")'s Type is not same in " + member.getAttribute().declaringClass() + " and " + t.declaringClass());
}
}
this.decoders[i] = decoder;