use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class NewObjectNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
if (newObjectOptimizer == null) {
if (egressType == null) {
if (factory != null && factory.isResolveable(typeDescr.getClassName())) {
try {
egressType = (Class) factory.getVariableResolver(typeDescr.getClassName()).getValue();
rewriteClassReferenceToFQCN(COMPILE_IMMEDIATE);
if (typeDescr.isArray()) {
try {
egressType = findClass(factory, repeatChar('[', typeDescr.getArrayLength()) + "L" + egressType.getName() + ";", null);
} catch (Exception e) {
// for now, don't handle this.
}
}
} catch (ClassCastException e) {
throw new CompileException("cannot construct object: " + typeDescr.getClassName() + " is not a class reference", expr, start, e);
}
}
}
if (typeDescr.isArray()) {
return (newObjectOptimizer = new NewObjectArray(getBaseComponentType(egressType.getComponentType()), typeDescr.getCompiledArraySize())).getValue(ctx, thisValue, factory);
}
try {
AccessorOptimizer optimizer = getThreadAccessorOptimizer();
ParserContext pCtx = new ParserContext();
pCtx.getParserConfiguration().setAllImports(getInjectedImports(factory));
newObjectOptimizer = optimizer.optimizeObjectCreation(pCtx, name, 0, name.length, ctx, thisValue, factory);
/**
* Check to see if the optimizer actually produced the object during optimization. If so,
* we return that value now.
*/
if (optimizer.getResultOptPass() != null) {
egressType = optimizer.getEgressType();
return optimizer.getResultOptPass();
}
} catch (CompileException e) {
throw ErrorUtil.rewriteIfNeeded(e, expr, start);
} finally {
OptimizerFactory.clearThreadAccessorOptimizer();
}
}
return newObjectOptimizer.getValue(ctx, thisValue, factory);
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class NewObjectNode method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
try {
if (typeDescr.isArray()) {
Class cls = findClass(factory, typeDescr.getClassName(), null);
int[] s = new int[typeDescr.getArrayLength()];
ArraySize[] arraySize = typeDescr.getArraySize();
for (int i = 0; i < s.length; i++) {
s[i] = convert(eval(arraySize[i].value, ctx, factory), Integer.class);
}
return newInstance(cls, s);
} else {
String[] cnsRes = captureContructorAndResidual(name, 0, name.length);
List<char[]> constructorParms = parseMethodOrConstructor(cnsRes[0].toCharArray());
if (constructorParms != null) {
Class cls = findClass(factory, new String(subset(name, 0, findFirst('(', 0, name.length, name))).trim(), null);
Object[] parms = new Object[constructorParms.size()];
for (int i = 0; i < constructorParms.size(); i++) {
parms[i] = eval(constructorParms.get(i), ctx, factory);
}
Constructor cns = getBestConstructorCandidate(parms, cls, false);
if (cns == null)
throw new CompileException("unable to find constructor for: " + cls.getName(), expr, start);
for (int i = 0; i < parms.length; i++) {
// noinspection unchecked
parms[i] = convert(parms[i], cns.getParameterTypes()[i]);
}
if (cnsRes.length > 1) {
return PropertyAccessor.get(cnsRes[1], cns.newInstance(parms), factory, thisValue);
} else {
return cns.newInstance(parms);
}
} else {
Constructor<?> cns = Class.forName(typeDescr.getClassName(), true, currentThread().getContextClassLoader()).getConstructor(EMPTYCLS);
if (cnsRes.length > 1) {
return PropertyAccessor.get(cnsRes[1], cns.newInstance(), factory, thisValue);
} else {
return cns.newInstance();
}
}
}
} catch (CompileException e) {
throw e;
} catch (ClassNotFoundException e) {
throw new CompileException("unable to resolve class: " + e.getMessage(), expr, start, e);
} catch (NoSuchMethodException e) {
throw new CompileException("cannot resolve constructor: " + e.getMessage(), expr, start, e);
} catch (Exception e) {
throw new CompileException("could not instantiate class: " + e.getMessage(), expr, start, e);
}
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class Fuzzer method main.
public static void main(String[] args) throws IOException {
DecimalFormat df = new DecimalFormat("###,###.##");
StringAppender append = new StringAppender();
int len;
long start = currentTimeMillis();
long time;
double rate;
int seed;
boolean flip = false;
Random rand = new Random(System.currentTimeMillis());
Random rand1 = new Random(System.currentTimeMillis() + 1);
Random rand2 = new Random(rand1.nextInt());
Random rand3 = new Random(rand.nextInt(SALTS.length - 1));
Random rand4 = new Random(rand3.nextInt());
for (int run = 0; run < MAX; run++) {
len = (int) (random() * 500) + 10;
append.reset();
for (int i = 0; i < len; i++) {
append.append(CHAR_TABLE[((SALTS[((rand.nextInt(1000)) + 1) % SALTS.length]) * ((flip = !flip) ? rand1.nextInt(1000) : rand2.nextInt(1000)) + 1) % CHAR_TABLE.length]);
SALTS[rand3.nextInt(SALTS.length - 1)] ^= rand4.nextInt(1000) + 1;
}
try {
MVEL.eval(append.toString());
} catch (UnresolveablePropertyException e) {
// ignore
} catch (CompileException e) {
// ignore
} catch (ArithmeticException e) {
// ignore
} catch (ScriptRuntimeException e) {
// ignore
} catch (Exception e) {
System.out.println("untrapped error!\n---\n" + append.toString() + "\n---\n");
System.out.flush();
e.printStackTrace();
System.err.flush();
}
if (run % 25000 == 0 && run != 0) {
rate = run / (time = (currentTimeMillis() - start) / 1000);
System.out.println("Run: " + df.format(run) + " times; " + df.format(time) + "secs; " + df.format(rate) + " avg. per second.");
}
}
}
Aggregations