[ductilej] push by samskivert - We can have our friendly error message cake and eat our performance ca... on 2010-07-10 18:53 GMT

1 view
Skip to first unread message

duct...@googlecode.com

unread,
Jul 10, 2010, 2:53:26 PM7/10/10
to ductil...@googlegroups.com
Revision: be7c95ab71
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 11:53:05 2010
Log: We can have our friendly error message cake and eat our performance
cake too.
http://code.google.com/p/ductilej/source/detail?r=be7c95ab71

Modified:
/src/org/ductilej/runtime/Binop.java
/src/org/ductilej/runtime/Unop.java

=======================================
--- /src/org/ductilej/runtime/Binop.java Sat Jul 10 11:48:44 2010
+++ /src/org/ductilej/runtime/Binop.java Sat Jul 10 11:53:05 2010
@@ -144,14 +144,14 @@
* Returns the {@link BinOps} instance appropriate for the supplied
left- and right-hand-sides
* of a binary expression.
*/
- protected static BinOps get (Object lhs, Object rhs)
- {
- // TODO: we probably want this check here, though it will hurt
performance
- // if (lhs == null || rhs == null) {
- // throw new NullPointerException(
- // "Binary op (" + opcode + ") on null arg (lhs=" + lhs
+ ", rhs=" + rhs + ")");
- // }
- return BINOPS.get(lhs.getClass()).get(rhs.getClass());
+ protected BinOps get (Object lhs, Object rhs)
+ {
+ try {
+ return BINOPS.get(lhs.getClass()).get(rhs.getClass());
+ } catch (NullPointerException npe) {
+ throw new NullPointerException(
+ "Binary op (" + this + ") on null arg (lhs=" + lhs + ",
rhs=" + rhs + ")");
+ }
}

/**
=======================================
--- /src/org/ductilej/runtime/Unop.java Sat Jul 10 11:48:44 2010
+++ /src/org/ductilej/runtime/Unop.java Sat Jul 10 11:53:05 2010
@@ -67,13 +67,13 @@
/**
* Returns the {@link UnOps} instance appropriate for the supplied
expression argument type.
*/
- protected static UnOps get (Object arg)
- {
- // TODO: we probably want this check here, though it will hurt
performance
- // if (arg == null) {
- // throw new NullPointerException("Unary op (" + opcode + ")
on null arg.");
- // }
- return UNOPS.get(arg.getClass());
+ protected UnOps get (Object arg)
+ {
+ try {
+ return UNOPS.get(arg.getClass());
+ } catch (NullPointerException npe) {
+ throw new NullPointerException("Unary op (" + this + ") on
null arg.");
+ }
}

protected static final Map<Class<?>, UnOps> UNOPS =
ImmutableMap.<Class<?>, UnOps>builder().

Reply all
Reply to author
Forward
0 new messages