Fix crash when toString returns null value (#8067)
* Fix crash when toString returns null value * Return a string from NullUnit toString * Begone redundancy * Unwrap before null check to ensure non-nullability
This commit is contained in:
@@ -882,7 +882,7 @@ public class EntityProcess extends BaseProcessor{
|
|||||||
|
|
||||||
for(Smethod method : methods){
|
for(Smethod method : methods){
|
||||||
String signature = method.toString();
|
String signature = method.toString();
|
||||||
if(signatures.contains(signature)) continue;
|
if(!signatures.add(signature)) continue;
|
||||||
|
|
||||||
Stype compType = interfaceToComp(method.type());
|
Stype compType = interfaceToComp(method.type());
|
||||||
MethodSpec.Builder builder = MethodSpec.overriding(method.e).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
MethodSpec.Builder builder = MethodSpec.overriding(method.e).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||||
@@ -893,25 +893,29 @@ public class EntityProcess extends BaseProcessor{
|
|||||||
builder.addAnnotation(OverrideCallSuper.class); //just in case
|
builder.addAnnotation(OverrideCallSuper.class); //just in case
|
||||||
|
|
||||||
if(!method.isVoid()){
|
if(!method.isVoid()){
|
||||||
if(method.name().equals("isNull")){
|
String methodName = method.name();
|
||||||
builder.addStatement("return true");
|
switch(methodName){
|
||||||
}else if(method.name().equals("id")){
|
case "isNull":
|
||||||
|
builder.addStatement("return true");
|
||||||
|
break;
|
||||||
|
case "id":
|
||||||
builder.addStatement("return -1");
|
builder.addStatement("return -1");
|
||||||
}else{
|
break;
|
||||||
Svar variable = compType == null || method.params().size > 0 ? null : compType.fields().find(v -> v.name().equals(method.name()));
|
case "toString":
|
||||||
String desc = variable == null ? null : variable.descString();
|
builder.addStatement("return $S", className);
|
||||||
if(variable == null || !varInitializers.containsKey(desc)){
|
break;
|
||||||
builder.addStatement("return " + getDefault(method.ret().toString()));
|
default:
|
||||||
}else{
|
Svar variable = compType == null || method.params().size > 0 ? null : compType.fields().find(v -> v.name().equals(methodName));
|
||||||
String init = varInitializers.get(desc);
|
String desc = variable == null ? null : variable.descString();
|
||||||
builder.addStatement("return " + (init.equals("{}") ? "new " + variable.mirror().toString() : "") + init);
|
if(variable == null || !varInitializers.containsKey(desc)){
|
||||||
}
|
builder.addStatement("return " + getDefault(method.ret().toString()));
|
||||||
|
}else{
|
||||||
|
String init = varInitializers.get(desc);
|
||||||
|
builder.addStatement("return " + (init.equals("{}") ? "new " + variable.mirror().toString() : "") + init);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nullBuilder.addMethod(builder.build());
|
nullBuilder.addMethod(builder.build());
|
||||||
|
|
||||||
signatures.add(signature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nullsBuilder.addField(FieldSpec.builder(type, Strings.camelize(baseName)).initializer("new " + className + "()").addModifiers(Modifier.FINAL, Modifier.STATIC, Modifier.PUBLIC).build());
|
nullsBuilder.addField(FieldSpec.builder(type, Strings.camelize(baseName)).initializer("new " + className + "()").addModifiers(Modifier.FINAL, Modifier.STATIC, Modifier.PUBLIC).build());
|
||||||
|
|||||||
@@ -45,8 +45,10 @@ public class Scripts implements Disposable{
|
|||||||
try{
|
try{
|
||||||
Object o = context.evaluateString(scope, text, "console.js", 1);
|
Object o = context.evaluateString(scope, text, "console.js", 1);
|
||||||
if(o instanceof NativeJavaObject n) o = n.unwrap();
|
if(o instanceof NativeJavaObject n) o = n.unwrap();
|
||||||
if(o instanceof Undefined) o = "undefined";
|
if(o == null) o = "null";
|
||||||
return String.valueOf(o);
|
else if(o instanceof Undefined) o = "undefined";
|
||||||
|
var out = o.toString();
|
||||||
|
return out == null ? "null" : out;
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
return getError(t, false);
|
return getError(t, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user