diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/SpecializationMethodParser.java @ 18770:2c669386b5d0

Truffle-DSL: fix crash if type in rewriteOn is not of type Throwable. Improved error messages for Specialization#rewriteOn.
author Christian Humer <christian.humer@gmail.com>
date Fri, 02 Jan 2015 14:31:51 +0100
parents 2db61eddcb97
children 08aa0372dad4
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/SpecializationMethodParser.java	Wed Dec 31 17:35:10 2014 +0000
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/SpecializationMethodParser.java	Fri Jan 02 14:31:51 2015 +0100
@@ -59,14 +59,25 @@
         AnnotationValue rewriteValue = ElementUtils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn");
         List<TypeMirror> exceptionTypes = ElementUtils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn");
         List<SpecializationThrowsData> exceptionData = new ArrayList<>();
+        List<TypeMirror> rewriteOnTypes = new ArrayList<>();
         for (TypeMirror exceptionType : exceptionTypes) {
             SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType);
             if (!ElementUtils.canThrowType(method.getMethod().getThrownTypes(), exceptionType)) {
-                throwsData.addError("Method must specify a throws clause with the exception type '%s'.", ElementUtils.getQualifiedName(exceptionType));
+                method.addError("A rewriteOn checked exception was specified but not thrown in the method's throws clause. The @%s method must specify a throws clause with the exception type '%s'.",
+                                Specialization.class.getSimpleName(), ElementUtils.getQualifiedName(exceptionType));
             }
+            rewriteOnTypes.add(throwsData.getJavaClass());
             exceptionData.add(throwsData);
         }
 
+        for (TypeMirror typeMirror : method.getMethod().getThrownTypes()) {
+            if (!ElementUtils.canThrowType(rewriteOnTypes, typeMirror)) {
+                method.addError(rewriteValue,
+                                "A checked exception '%s' is thrown but is not specified using the rewriteOn property. Checked exceptions that are not used for rewriting are not handled by the DSL. Use RuntimeExceptions for this purpose instead.",
+                                ElementUtils.getQualifiedName(typeMirror));
+            }
+        }
+
         Collections.sort(exceptionData, new Comparator<SpecializationThrowsData>() {
 
             @Override