use of org.mvel2.UnresolveablePropertyException in project mvel by mvel.
the class DefaultLocalVariableResolverFactory method createVariable.
public VariableResolver createVariable(String name, Object value, Class<?> type) {
if (indexedVariableNames == null)
return super.createVariable(name, value, type);
VariableResolver vr;
boolean newVar = false;
try {
int idx;
if ((idx = variableIndexOf(name)) != -1) {
vr = new SimpleValueResolver(value);
if (indexedVariableResolvers[idx] == null) {
indexedVariableResolvers[idx] = vr;
}
variableResolvers.put(indexedVariableNames[idx], vr);
vr = indexedVariableResolvers[idx];
newVar = true;
} else {
return super.createVariable(name, value, type);
}
} catch (UnresolveablePropertyException e) {
vr = null;
}
if (!newVar && vr != null && vr.getType() != null) {
throw new RuntimeException("variable already defined within scope: " + vr.getType() + " " + name);
} else {
addResolver(name, vr = new MapVariableResolver(variables, name, type)).setValue(value);
return vr;
}
}
use of org.mvel2.UnresolveablePropertyException in project mvel by mvel.
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) {
long l = time = (currentTimeMillis() - start) / 1000;
if (l == 0) {
l = 1;
}
rate = run / l;
System.out.println("Run: " + df.format(run) + " times; " + df.format(time) + "secs; " + df.format(rate) + " avg. per second.");
}
}
}
use of org.mvel2.UnresolveablePropertyException in project mvel by mikebrock.
the class DefaultLocalVariableResolverFactory method createVariable.
public VariableResolver createVariable(String name, Object value, Class<?> type) {
if (indexedVariableNames == null)
return super.createVariable(name, value, type);
VariableResolver vr;
boolean newVar = false;
try {
int idx;
if ((idx = variableIndexOf(name)) != -1) {
vr = new SimpleValueResolver(value);
if (indexedVariableResolvers[idx] == null) {
indexedVariableResolvers[idx] = vr;
}
variableResolvers.put(indexedVariableNames[idx], vr);
vr = indexedVariableResolvers[idx];
newVar = true;
} else {
return super.createVariable(name, value, type);
}
} catch (UnresolveablePropertyException e) {
vr = null;
}
if (!newVar && vr != null && vr.getType() != null) {
throw new RuntimeException("variable already defined within scope: " + vr.getType() + " " + name);
} else {
addResolver(name, vr = new MapVariableResolver(variables, name, type)).setValue(value);
return vr;
}
}
use of org.mvel2.UnresolveablePropertyException 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