From 48fbe4abbd41c8faa0065a2be4f11839268bd0c7 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 24 Jan 2012 21:34:06 +0000 Subject: Stricter property type checking, preventing verification errors in generated classes. --- .../com/amazon/carbonado/info/StorableIntrospector.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/main/java/com') diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java index 5ad6d20..1ec0575 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java @@ -1010,6 +1010,13 @@ public class StorableIntrospector { ("Must define proper 'get' method for property: " + property.getName()); } } else { + if (readMethod.getReturnType() != property.getType()) { + errorMessages.add + ("Property type doesn't match accessor method return type: " + + property.getType().getName() + " != " + readMethod.getReturnType().getName() + + " for " + readMethod); + } + nullable = readMethod.getAnnotation(Nullable.class); alias = readMethod.getAnnotation(Alias.class); version = readMethod.getAnnotation(Version.class); @@ -1062,6 +1069,16 @@ public class StorableIntrospector { } } } else { + Class[] writeParams = writeMethod.getParameterTypes(); + if (writeParams == null || writeParams.length != 1) { + errorMessages.add("Mutator method must contain one parameter: " + writeMethod); + } else if (writeParams[0] != property.getType()) { + errorMessages.add + ("Property type doesn't match mutator method parameter: " + + property.getType().getName() + " != " + writeParams[0].getName() + + " for " + writeMethod); + } + if (writeMethod.getAnnotation(Nullable.class) != null) { errorMessages.add ("Nullable annotation not allowed on mutator: " + writeMethod); -- cgit v1.2.3