Search in sources :

Example 1 with UnresolveablePropertyException

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;
    }
}
Also used : UnresolveablePropertyException(org.mvel2.UnresolveablePropertyException) VariableResolver(org.mvel2.integration.VariableResolver)

Example 2 with UnresolveablePropertyException

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.");
        }
    }
}
Also used : Random(java.util.Random) ScriptRuntimeException(org.mvel2.ScriptRuntimeException) DecimalFormat(java.text.DecimalFormat) StringAppender(org.mvel2.util.StringAppender) CompileException(org.mvel2.CompileException) UnresolveablePropertyException(org.mvel2.UnresolveablePropertyException) UnresolveablePropertyException(org.mvel2.UnresolveablePropertyException) ScriptRuntimeException(org.mvel2.ScriptRuntimeException) IOException(java.io.IOException) CompileException(org.mvel2.CompileException)

Example 3 with UnresolveablePropertyException

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;
    }
}
Also used : UnresolveablePropertyException(org.mvel2.UnresolveablePropertyException) VariableResolver(org.mvel2.integration.VariableResolver)

Example 4 with UnresolveablePropertyException

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.");
        }
    }
}
Also used : Random(java.util.Random) ScriptRuntimeException(org.mvel2.ScriptRuntimeException) DecimalFormat(java.text.DecimalFormat) StringAppender(org.mvel2.util.StringAppender) CompileException(org.mvel2.CompileException) UnresolveablePropertyException(org.mvel2.UnresolveablePropertyException) UnresolveablePropertyException(org.mvel2.UnresolveablePropertyException) ScriptRuntimeException(org.mvel2.ScriptRuntimeException) IOException(java.io.IOException) CompileException(org.mvel2.CompileException)

Aggregations

UnresolveablePropertyException (org.mvel2.UnresolveablePropertyException)4 IOException (java.io.IOException)2 DecimalFormat (java.text.DecimalFormat)2 Random (java.util.Random)2 CompileException (org.mvel2.CompileException)2 ScriptRuntimeException (org.mvel2.ScriptRuntimeException)2 VariableResolver (org.mvel2.integration.VariableResolver)2 StringAppender (org.mvel2.util.StringAppender)2