diff --git a/src/java/com/samskivert/depot/util/RuntimeUtil.java b/src/java/com/samskivert/depot/util/RuntimeUtil.java index 91a484f..a465180 100644 --- a/src/java/com/samskivert/depot/util/RuntimeUtil.java +++ b/src/java/com/samskivert/depot/util/RuntimeUtil.java @@ -69,8 +69,8 @@ public class RuntimeUtil /** * Creates a function that creates an instance of R and initializes all accessible (ie. public) * fields of R from fields of P with matching name. If the function is applied to null, null - * will be returned. Fields of P that do not exist in R will be ignored and vice versa. See the - * class documentation for a list of field conversions that will be made automatically and the + * will be returned. Fields of P that do not exist in R will be ignored. See the class + * documentation for a list of field conversions that will be made automatically and the * mechanism for performing other conversions. */ public static

Function makeToRuntime ( @@ -86,9 +86,7 @@ public class RuntimeUtil try { R object = rclass.newInstance(); for (int ii = 0, ll = rfields.length; ii < ll; ii++) { - if (getters[ii] != null) { - rfields[ii].set(object, getters[ii].get(record)); - } + rfields[ii].set(object, getters[ii].get(record)); } return object; } catch (Exception e) { @@ -118,9 +116,7 @@ public class RuntimeUtil try { P record = pclass.newInstance(); for (int ii = 0, ll = rfields.length; ii < ll; ii++) { - if (setters[ii] != null) { - setters[ii].set(record, rfields[ii].get(object)); - } + setters[ii].set(record, rfields[ii].get(object)); } return record; } catch (Exception e) { @@ -181,7 +177,10 @@ public class RuntimeUtil // if we have no persistent field for the runtime field, we're now out of luck if (pfield == null) { - return null; + throw new IllegalArgumentException( + "Cannot create mapping for " + rfield + ". Neither " + + pclass.getSimpleName() + "." + rfield.getName() + " nor " + + rfield.getType() + " " + getter + "() exist."); } // if the fields match exactly, return a getter that just gets the field @@ -204,7 +203,7 @@ public class RuntimeUtil } // if we have exhausted all other approaches, we're SOL - return null; + throw new IllegalArgumentException("Cannot map " + pfield + " to " + rfield + "."); } protected static Setter makeSetter (Class pclass, final Field pfield, Field rfield) @@ -224,7 +223,8 @@ public class RuntimeUtil // if we have no persistent field for this runtime field, we're now out of luck if (pfield == null) { - return null; + throw new IllegalArgumentException("Cannot create setter for " + rfield + ". " + + "No corresponding field exists in " + pclass + "."); } // if the fields match exactly, return a setter that just sets the field @@ -247,7 +247,7 @@ public class RuntimeUtil } // if we have exhausted all other approaches, we're SOL - return null; + throw new IllegalArgumentException("Cannot map " + rfield + " to " + pfield + "."); } protected static Field[] getPersistentFields (Class pclass, Field[] rfields)