< prev index next >

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

Print this page

        

@@ -44,23 +44,43 @@
     protected final boolean isFinal;
 
     UnsafeFieldAccessorImpl(Field field) {
         this.field = field;
         if (Modifier.isStatic(field.getModifiers()))
-            fieldOffset = unsafe.staticFieldOffset(field);
+            this.fieldOffset = unsafe.staticFieldOffset(field);
         else
-            fieldOffset = unsafe.objectFieldOffset(field);
-        isFinal = Modifier.isFinal(field.getModifiers());
+            this.fieldOffset = unsafe.objectFieldOffset(field);
+        this.isFinal = Modifier.isFinal(field.getModifiers());
     }
 
     protected void ensureObj(Object o) {
         // NOTE: will throw NullPointerException, as specified, if o is null
         if (!field.getDeclaringClass().isAssignableFrom(o.getClass())) {
             throwSetIllegalArgumentException(o);
         }
     }
 
+    protected boolean isFlattened() {
+        return unsafe.isFlattened(field);
+    }
+
+    protected boolean canBeNull() {
+        return field.getType().isNullableType();
+    }
+
+    protected Object checkValue(Object value) {
+        if (!canBeNull() && value == null)
+            throw new NullPointerException(field + " cannot be set to null");
+
+        if (value != null) {
+            if (!field.getType().isAssignableFrom(value.getClass())) {
+                throwSetIllegalArgumentException(value);
+            }
+        }
+        return value;
+    }
+
     private String getQualifiedFieldName() {
       return field.getDeclaringClass().getName() + "." +field.getName();
     }
 
     protected IllegalArgumentException newGetIllegalArgumentException(String type) {
< prev index next >