add null checks to asm constructors

This commit is contained in:
wea_ondara
2022-11-24 14:17:26 +01:00
parent 038ebe4aff
commit a1e3377599

View File

@@ -2,6 +2,7 @@ package jef.asm;
import jef.serializable.SerializableFunction;
import jef.serializable.SerializablePredicate;
import jef.util.Check;
import lombok.Getter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
@@ -18,18 +19,18 @@ public class AsmParser {
private final Method method;
public AsmParser(SerializablePredicate<?> predicate) {
this.lambda = predicate;
this.lambda = Check.notNull(predicate, "predicate");
this.method = null;
}
public AsmParser(SerializableFunction<?, ?> function) {
this.lambda = function;
this.lambda = Check.notNull(function, "function");
this.method = null;
}
public AsmParser(Method method) {
this.lambda = null;
this.method = method;
this.method = Check.notNull(method, "method");
}
public AsmParseResult parse() throws AsmParseException {
@@ -39,7 +40,7 @@ public class AsmParser {
} else if (this.method != null) {
return parseMethodExpression();
}
throw new IllegalStateException();
throw new IllegalStateException("Illegal state");
} catch (Exception e) {
throw new AsmParseException("PredicateParser: failed to parse expression: " + e.getLocalizedMessage(), e);
}
@@ -58,11 +59,7 @@ public class AsmParser {
cls = Class.forName(classname.replace("/", "."));
var is = loader.getResourceAsStream(cls.getName().replace(".", "/") + ".class");
var cr = new ClassReader(is);
var visiter = new FilterClassVisitor(Opcodes.ASM9, lambdaname, args);
cr.accept(visiter, 0);
return visiter.getResult();
return parseCommon(is, lambdaname, args);
}
private AsmParseResult parseMethodExpression() throws Exception {