Generate not-null assertions after getting a field

This commit is contained in:
Alexander Udalov
2012-10-02 22:09:02 +04:00
parent 27bea0a607
commit fcbc95bbb4
5 changed files with 31 additions and 1 deletions
+9 -1
View File
@@ -43,6 +43,14 @@ public class Intrinsics {
}
}
public static void checkFieldIsNotNull(Object value, String className, String fieldName) {
if (value == null) {
IllegalStateException exception =
new IllegalStateException("Field specified as non-null contains null: " + className + "." + fieldName);
throw sanitizeStackTrace(exception);
}
}
public static <T> Class<T> getJavaClass(T self) {
return (Class<T>) self.getClass();
}
@@ -66,7 +74,7 @@ public class Intrinsics {
}
private static final Set<String> METHOD_NAMES_TO_SKIP = new HashSet<String>(Arrays.asList(
"throwNpe", "checkReturnedValueIsNotNull"
"throwNpe", "checkReturnedValueIsNotNull", "checkFieldIsNotNull"
));
private static <T extends Throwable> T sanitizeStackTrace(T throwable) {