commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1392536 - in /commons/sandbox/nabla/trunk/src: main/java/org/apache/commons/nabla/ main/java/org/apache/commons/nabla/forward/analysis/ main/resources/assets/org/apache/commons/nabla/ test/java/org/apache/commons/nabla/
Date Mon, 01 Oct 2012 19:28:24 GMT
Author: luc
Date: Mon Oct  1 19:28:23 2012
New Revision: 1392536

URL: http://svn.apache.org/viewvc?rev=1392536&view=rev
Log:
Use the general exception mechanism for errors copied from ASM.

Modified:
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/DifferentiationException.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMessages.java
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/TrackingInterpreter.java
    commons/sandbox/nabla/trunk/src/main/resources/assets/org/apache/commons/nabla/NablaMessages_fr.properties
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/NablaMessagesTest.java

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/DifferentiationException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/DifferentiationException.java?rev=1392536&r1=1392535&r2=1392536&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/DifferentiationException.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/DifferentiationException.java
Mon Oct  1 19:28:23 2012
@@ -72,4 +72,73 @@ public class DifferentiationException ex
         return context.getLocalizedMessage();
     }
 
+    /** Create an {@link java.lang.IllegalArgumentException} with localized message.
+     * @param specifier format specifier (to be translated)
+     * @param parts parts to insert in the format (no translation)
+     * @return an {@link java.lang.IllegalArgumentException} with localized message
+     */
+    public static IllegalArgumentException createIllegalArgumentException(final Localizable
specifier,
+                                                                          final Object ...
parts) {
+        return new IllegalArgumentException() {
+
+            /** Serializable UID. */
+            private static final long serialVersionUID = 20121001L;
+
+            /** {@inheritDoc} */
+            @Override
+            public String getMessage() {
+                final ExceptionContext context = new ExceptionContext(this);
+                context.addMessage(specifier, parts);
+                return context.getMessage();
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public String getLocalizedMessage() {
+                final ExceptionContext context = new ExceptionContext(this);
+                context.addMessage(specifier, parts);
+                return context.getLocalizedMessage();
+            }
+
+        };
+
+    }
+
+    /** Create an {@link java.lang.RuntimeException} for an internal error.
+     * @param cause underlying cause
+     * @return an {@link java.lang.RuntimeException} for an internal error
+     */
+    public static RuntimeException createInternalError(final Throwable cause) {
+
+        /** Format specifier (to be translated). */
+        final Localizable SPECIFIER = NablaMessages.INTERNAL_ERROR;
+
+        /** URL for reporting problems. */
+        final String REPORT_URL = "https://issues.apache.org/jira/browse/SANDBOX/component/12312280";
+
+        return new RuntimeException() {
+
+            /** Serializable UID. */
+            private static final long serialVersionUID = 20121001L;
+
+            /** {@inheritDoc} */
+            @Override
+            public String getMessage() {
+                final ExceptionContext context = new ExceptionContext(this);
+                context.addMessage(SPECIFIER, REPORT_URL);
+                return context.getMessage();
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public String getLocalizedMessage() {
+                final ExceptionContext context = new ExceptionContext(this);
+                context.addMessage(SPECIFIER, REPORT_URL);
+                return context.getLocalizedMessage();
+            }
+
+        };
+
+    }
+
 }

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMessages.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMessages.java?rev=1392536&r1=1392535&r2=1392536&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMessages.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMessages.java
Mon Oct  1 19:28:23 2012
@@ -56,7 +56,9 @@ public enum NablaMessages implements Loc
     INDEX_OF_LOCAL_VARIABLE_OUT_OF_RANGE("index of size {0} local variable ({1}) outside
of [{2}, {3}] range"),
     UNEXPECTED_INSTRUCTION("unexpected instruction with opcode {0}"),
     UNABLE_TO_HANDLE_INSTRUCTION("unable to handle instruction with opcode {0}"),
-    CANNOT_GET_VOID_FIELD("unable to get value of void type field {0}");
+    CANNOT_GET_VOID_FIELD("unable to get value of void type field {0}"),
+    ILLEGAL_LDC_CONSTANT("illegal LDC constant {0}"),
+    INTERNAL_ERROR("internal error, please fill a bug report at {0}");
 
     // CHECKSTYLE: resume JavadocVariable
     // CHECKSTYLE: resume MultipleVariableDeclarations

Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/TrackingInterpreter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/TrackingInterpreter.java?rev=1392536&r1=1392535&r2=1392536&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/TrackingInterpreter.java
(original)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/TrackingInterpreter.java
Mon Oct  1 19:28:23 2012
@@ -19,6 +19,8 @@ package org.apache.commons.nabla.forward
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.nabla.DifferentiationException;
+import org.apache.commons.nabla.NablaMessages;
 import org.objectweb.asm.Handle;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
@@ -68,6 +70,7 @@ import org.objectweb.asm.tree.analysis.I
  * THE POSSIBILITY OF SUCH DAMAGE.
  * </p>
  * @see TrackingValue
+ * @version $Id$
  */
 public class TrackingInterpreter extends Interpreter<TrackingValue> {
 
@@ -132,12 +135,14 @@ public class TrackingInterpreter extends
                     } else if (sort == Type.METHOD) {
                         return new TrackingValue(Type.getObjectType("java/lang/invoke/MethodType"),
insn);
                     } else {
-                        throw new IllegalArgumentException("Illegal LDC constant " + cst);
+                        throw DifferentiationException.createIllegalArgumentException(NablaMessages.ILLEGAL_LDC_CONSTANT,
+                                                                                      cst);
                     }
                 } else if (cst instanceof Handle) {
                     return new TrackingValue(Type.getObjectType("java/lang/invoke/MethodHandle"),
insn);
                 } else {
-                    throw new IllegalArgumentException("Illegal LDC constant " + cst);
+                    throw DifferentiationException.createIllegalArgumentException(NablaMessages.ILLEGAL_LDC_CONSTANT,
+                                                                                  cst);
                 }
             case Opcodes.JSR:
                 return new TrackingValue(Type.VOID_TYPE, insn); // return address value
@@ -146,7 +151,7 @@ public class TrackingInterpreter extends
             case Opcodes.NEW:
                 return new TrackingValue(Type.getObjectType(((TypeInsnNode) insn).desc),
insn);
             default:
-                throw new Error("Internal error.");
+                throw DifferentiationException.createInternalError(null);
         }
     }
 
@@ -235,7 +240,7 @@ public class TrackingInterpreter extends
             case Opcodes.IFNONNULL:
                 return null;
             default:
-                throw new Error("Internal error.");
+                throw DifferentiationException.createInternalError(null);
         }
     }
 
@@ -308,7 +313,7 @@ public class TrackingInterpreter extends
             case Opcodes.PUTFIELD:
                 return null;
             default:
-                throw new Error("Internal error.");
+                throw DifferentiationException.createInternalError(null);
         }
     }
 

Modified: commons/sandbox/nabla/trunk/src/main/resources/assets/org/apache/commons/nabla/NablaMessages_fr.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/resources/assets/org/apache/commons/nabla/NablaMessages_fr.properties?rev=1392536&r1=1392535&r2=1392536&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/resources/assets/org/apache/commons/nabla/NablaMessages_fr.properties
(original)
+++ commons/sandbox/nabla/trunk/src/main/resources/assets/org/apache/commons/nabla/NablaMessages_fr.properties
Mon Oct  1 19:28:23 2012
@@ -28,3 +28,5 @@ INDEX_OF_LOCAL_VARIABLE_OUT_OF_RANGE = i
 UNEXPECTED_INSTRUCTION = instruction ayant l''opcode {0} inattendue
 UNABLE_TO_HANDLE_INSTRUCTION = incapable de g\u00e9rer une instruction ayant l''opcode {0}
 CANNOT_GET_VOID_FIELD = impossible de r\u00e9cup\u00e9rer la valeur du champ {0} de type
void
+ILLEGAL_LDC_CONSTANT = constante ill\u00e9gale pour une instruction LDC : {0}
+INTERNAL_ERROR = erreur interne, veuillez signaler l''erreur \u00e0 {0}

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/NablaMessagesTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/NablaMessagesTest.java?rev=1392536&r1=1392535&r2=1392536&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/NablaMessagesTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/NablaMessagesTest.java
Mon Oct  1 19:28:23 2012
@@ -36,7 +36,7 @@ public class NablaMessagesTest {
 
     @Test
     public void testMessageNumber() {
-        Assert.assertEquals(15, NablaMessages.values().length);
+        Assert.assertEquals(17, NablaMessages.values().length);
     }
 
     @Test



Mime
View raw message