< prev index next >

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

Print this page
@@ -32,11 +32,12 @@
          super(field);
      }
  
      public Object get(Object obj) throws IllegalArgumentException {
          ensureObj(obj);
-         return unsafe.getReference(obj, fieldOffset);
+         return isFlattened() ? unsafe.getValue(obj, fieldOffset, field.getType())
+                              : unsafe.getReference(obj, fieldOffset, field.getType());
      }
  
      public boolean getBoolean(Object obj) throws IllegalArgumentException {
          throw newGetBooleanIllegalArgumentException();
      }

@@ -74,16 +75,16 @@
      {
          ensureObj(obj);
          if (isFinal) {
              throwFinalFieldIllegalAccessException(value);
          }
-         if (value != null) {
-             if (!field.getType().isAssignableFrom(value.getClass())) {
-                 throwSetIllegalArgumentException(value);
-             }
+         checkValue(value);
+         if (isFlattened()) {
+             unsafe.putValue(obj, fieldOffset, field.getType(), value);
+         } else {
+             unsafe.putReference(obj, fieldOffset, value);
          }
-         unsafe.putReference(obj, fieldOffset, value);
      }
  
      public void setBoolean(Object obj, boolean z)
          throws IllegalArgumentException, IllegalAccessException
      {
< prev index next >