[PATCH] [Fernflower] prevent null to be cast as short/byte

This commit is contained in:
Alexandru-Constantin Bledea
2017-10-25 19:42:06 +03:00
committed by Egor Ushakov
parent e7854376b8
commit c241278aee
6 changed files with 94 additions and 1 deletions

View File

@@ -877,7 +877,7 @@ public class ExprProcessor implements CodeConstants {
boolean quote = cast && exprent.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST);
// cast instead to 'byte' / 'short' when int constant is used as a value for 'Byte' / 'Short'
if (castNarrowing && exprent.type == Exprent.EXPRENT_CONST) {
if (castNarrowing && exprent.type == Exprent.EXPRENT_CONST && !((ConstExprent) exprent).isNull()) {
if (leftType.equals(VarType.VARTYPE_BYTE_OBJ)) {
leftType = VarType.VARTYPE_BYTE;
}

View File

@@ -247,6 +247,10 @@ public class ConstExprent extends Exprent {
throw new RuntimeException("invalid constant type: " + constType);
}
public boolean isNull() {
return CodeConstants.TYPE_NULL == constType.type;
}
private static String convertStringToJava(String value, boolean ascii) {
char[] arr = value.toCharArray();
StringBuilder buffer = new StringBuilder(arr.length);