Search in sources :

Example 1 with MalformedParametersException

use of java.lang.reflect.MalformedParametersException in project graal by oracle.

the class VerifyGetOptionsUsage method verify.

@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
    MetaAccessProvider metaAccess = context.getMetaAccess();
    ResolvedJavaType canonicalizerToolClass = metaAccess.lookupJavaType(CanonicalizerTool.class);
    boolean hasTool = false;
    try {
        for (ResolvedJavaMethod.Parameter parameter : graph.method().getParameters()) {
            if (parameter.getType().getName().equals(canonicalizerToolClass.getName())) {
                hasTool = true;
                break;
            }
        }
    } catch (MalformedParametersException e) {
    // Lambdas sometimes have malformed parameters so ignore this.
    }
    if (hasTool) {
        ResolvedJavaMethod getOptionsMethod = metaAccess.lookupJavaMethod(lookupMethod(Node.class, "getOptions"));
        for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = t.targetMethod();
            if (callee.equals(getOptionsMethod)) {
                if (hasTool) {
                    throw new VerificationError("Must use CanonicalizerTool.getOptions() instead of Node.getOptions() in method '%s' of class '%s'.", graph.method().getName(), graph.method().getDeclaringClass().getName());
                }
            }
        }
    }
    return true;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Node(org.graalvm.compiler.graph.Node) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) MalformedParametersException(java.lang.reflect.MalformedParametersException) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with MalformedParametersException

use of java.lang.reflect.MalformedParametersException in project jdk8u_jdk by JetBrains.

the class BadClassFiles method assertBadParameters.

public void assertBadParameters(Class<?> cls) throws NoSuchMethodException {
    try {
        System.err.println("Trying " + cls);
        final Method method = cls.getMethod("m", int.class, int.class);
        final Parameter[] params = method.getParameters();
        System.err.println("Name " + params[0].getName());
        System.err.println("Did not see expected exception");
        errors++;
    } catch (MalformedParametersException e) {
        System.err.println("Expected exception seen");
    }
}
Also used : Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method) MalformedParametersException(java.lang.reflect.MalformedParametersException)

Aggregations

MalformedParametersException (java.lang.reflect.MalformedParametersException)2 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Node (org.graalvm.compiler.graph.Node)1 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)1