< prev index next >

src/java.base/share/classes/jdk/internal/reflect/UnsafeFieldAccessorImpl.java

Print this page
*** 49,6 ***
--- 49,31 ---
          if (Modifier.isStatic(mods))
              fieldOffset = unsafe.staticFieldOffset(field);
          else
              fieldOffset = unsafe.objectFieldOffset(field);
      }
+ 
+     protected boolean isFlattened() {
+         return unsafe.isFlattened(field);
+     }
+ 
+     protected boolean canBeNull() {
+         return !field.getType().isPrimitiveClass() || field.getType().isPrimaryType();
+     }
+ 
+     protected Object checkValue(Object value) {
+         if (!canBeNull() && value == null)
+             throw new NullPointerException(field + " cannot be set to null");
+ 
+         if (value != null) {
+             Class<?> type = value.getClass();
+             if (type.isPrimitiveClass()) {
+                 type = type.asValueType();
+             }
+             if (!field.getType().isAssignableFrom(type)) {
+                 throwSetIllegalArgumentException(value);
+             }
+         }
+         return value;
+     }
+ 
  }
< prev index next >