Java Code Examples for java.lang.reflect.Field

The following are top voted examples for showing how to use java.lang.reflect.Field. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: elasticsearch-osem   File: OsemReflectionUtils.java View source code Vote up 6 votes
public static Field getField(Class clazz, String fieldName) {
    Set<Field> fields = getAllFields(clazz, withName(fieldName));
    Preconditions.checkArgument(fields.size() == 1, "Unable to find field {} for class {}", fieldName, clazz.getSimpleName());
    Field field = fields.iterator().next();
    field.setAccessible(true);
    return field;
}
 
Example 2
Project: elasticsearch-osem   File: OsemReflectionUtils.java View source code Vote up 6 votes
public static Object getFieldValue(Object object, Field field) {
    try {
        field.setAccessible(true);
        return field.get(object);
    } catch (IllegalAccessException e) {
        logger.error("Failed to get value from field", e);
        throw new ElasticSearchOsemException(e);
    }
}
 
Example 3
Project: SAPManagerPack   File: SAPReflectionHelper.java View source code Vote up 6 votes
public static <T, E> void setCachedFieldValue(Class<? super E> classToAccess, E instance, String mcpName, String srgName, T value) {
    Field field = getCachedField(classToAccess, mcpName, srgName);
    try {
        field.set(instance, value);
    } catch( Throwable ex ) {
        throw new UnableToSetFieldException(ex);
    }
}
 
Example 4
Project: elasticsearch-osem   File: MappingProcessor.java View source code Vote up 6 votes
private static Map<String, Object> getIndexableIdMap(Field field) {
    Map<String, Object> idMap = Maps.newHashMap();

    IndexableId indexableId = field.getAnnotation(IndexableId.class);
    if (indexableId.index() != IndexEnum.NA) {
        idMap.put("index", indexableId.index().toString().toLowerCase());
    }

    if (indexableId.store()) {
        idMap.put("store", "yes");
    }

    IndexableProperty indexableProperty = field.getAnnotation(IndexableProperty.class);
    if (indexableProperty != null) {
        String fieldName = field.getName();
        if (indexableProperty.name() != null && !indexableProperty.name().isEmpty()) {
            fieldName = indexableProperty.name();
        }
        idMap.put("path", fieldName);  // only need to put this if the IndexableId field is also IndexableProperty
    }

    return idMap;
}
 
Example 5
Project: elasticsearch-osem   File: OsemReflectionUtils.java View source code Vote up 6 votes
public static Class getGenericType(Field field) {
    if (!Collection.class.isAssignableFrom(field.getType())) {
        return field.getType();
    }
    ParameterizedType type = (ParameterizedType) field.getGenericType();
    return (Class) type.getActualTypeArguments()[0];
}
 
Example 6
Project: tapestry-model   File: ReflectionUtil.java View source code Vote up 6 votes
/**
 * Gets the all field names without annotation.
 * 
 * @param clazz
 *          the clazz
 * @param annotationClass
 *          the annotation class
 * @return the all field names without annotation
 */
public static List<String> getAllFieldNamesWithoutAnnotation(Class<?> clazz,
		Class<? extends Annotation> annotationClass) {
	String className = clazz.getName() + ".";
	List<String> fieldNames = new ArrayList<String>();

	for (Field field : getAllFields(clazz)) {
		if (!field.isAnnotationPresent(annotationClass)) {
			fieldNames.add(className + field.getName());
		}
	}

	return fieldNames;
}
 
Example 7
Project: OsmUi   File: mxObjectCodec.java View source code Vote up 6 votes
/**
 * Encodes the declared fields of the given object into the given node.
 * 
 * @param enc Codec that controls the encoding process.
 * @param obj Object whose fields should be encoded.
 * @param node XML node that contains the encoded object.
 */
protected void encodeFields(mxCodec enc, Object obj, Node node)
{
	Class<?> type = obj.getClass();

	while (type != null)
	{
		Field[] fields = type.getDeclaredFields();

		for (int i = 0; i < fields.length; i++)
		{
			Field f = fields[i];

			if ((f.getModifiers() & Modifier.TRANSIENT) != Modifier.TRANSIENT)
			{
				String fieldname = f.getName();
				Object value = getFieldValue(obj, fieldname);
				encodeValue(enc, obj, fieldname, value, node);
			}
		}

		type = type.getSuperclass();
	}
}
 
Example 8
Project: xapi   File: X_GC.java View source code Vote up 6 votes
@SuppressWarnings("unchecked")
public static <T> void deepDestroy(Class<? super T> classLiteral, T inst, HashSet<Object> seen) {
  for (Field f : classLiteral.getDeclaredFields()) {
    if (shouldSkip(f))continue;
    try {
      if (!f.isAccessible()) {
        f.setAccessible(true);
      }
      Object value = f.get(inst);
      if (value == null)continue;
      if (value instanceof Destroyable) {
        ((Destroyable)value).destroy();
      }
      if (value.getClass().getAnnotation(OnGC.class) != null) {
        destroy(Class.class.cast(value.getClass()), value);
      }
    } catch (Throwable e) {
      X_Debug.maybeRethrow(e);
    }
  }
}
 
Example 9
Project: jena   File: ParseException.java View source code Vote up 6 votes
/**
 * The  string from
 * [email protected] ARPErrorNumbers} associated with an integer error code
 * @param errNo An error code from [email protected] ARPErrorNumbers}.
 * @return The field name from [email protected] ARPErrorNumbers} with this error number, or null
 */
static public String errorCodeName(int errNo) {
    Class<?> c = ARPErrorNumbers.class;
    java.lang.reflect.Field flds[] = c.getDeclaredFields();
    for ( Field fld : flds )
    {
        try
        {
            if ( fld.getInt( null ) == errNo )
            {
                return fld.getName();
            }
        }
        catch ( Exception e )
        {
            // ignore exceptions
        }
    }
    return null;
}
 
Example 10
Project: BioWiki   File: CustomSpinner.java View source code Vote up 6 votes
private void ignoreOldSelectionByReflection() {
    try {
        Class<?> c = this.getClass().getSuperclass().getSuperclass().getSuperclass();
        Field reqField = c.getDeclaredField("mOldSelectedPosition");
        reqField.setAccessible(true);
        reqField.setInt(this, -1);
    } catch (Exception e) {
        AppLog.e(AppLog.T.MEDIA, e);
    }
}
 
Example 11
Project: xapi   File: FieldTests.java View source code Vote up 6 votes
@Test
public void testDirectInjection_Declared() throws Exception{
  final ReflectionCaseNoMagic superClass = new ReflectionCaseNoMagic();
  final Field field = NO_MAGIC.getDeclaredField(PRIVATE_MEMBER);
  field.setAccessible(true);
  assertFalse(field.getBoolean(superClass));
  field.setBoolean(superClass, true);
  assertTrue(field.getBoolean(superClass));
}
 
Example 12
Project: smack-xmpp   File: VCard.java View source code Vote up 6 votes
private void copyFieldsFrom(VCard from) {
    Field[] fields = VCard.class.getDeclaredFields();
    for (Field field : fields) {
        if (field.getDeclaringClass() == VCard.class &&
                !Modifier.isFinal(field.getModifiers())) {
            try {
                field.setAccessible(true);
                field.set(this, field.get(from));
            }
            catch (IllegalAccessException e) {
                throw new RuntimeException("This cannot happen:" + field, e);
            }
        }
    }
}
 
Example 13
Project: xapi   File: AnnotationTests.java View source code Vote up 6 votes
@Test
public void testAnnotationsKeepAll() throws Exception {
  final Class<?> testCase = magicClass(ReflectionCaseHasAllAnnos.class);
  final Field field = testCase.getDeclaredField("field");
  final Method method = testCase.getDeclaredMethod("method", Long.class);
  final Constructor<?> ctor = testCase.getDeclaredConstructor(long.class);
  Annotation[] annos = testCase.getAnnotations();
  assertHasAnno(testCase, annos, RuntimeRetention.class);
  if (GWT.isScript()) {
    // Gwt Dev can only access runtime level retention annotations
    assertHasAnno(testCase, annos, CompileRetention.class);
  }
  annos = field.getAnnotations();
  assertHasAnno(testCase, annos, RuntimeRetention.class);
  if (GWT.isScript()) {
    // Gwt Dev can only access runtime level retention annotations
    assertHasAnno(testCase, annos, CompileRetention.class);
  }

  annos = method.getAnnotations();
  assertHasAnno(testCase, annos, RuntimeRetention.class);
  if (GWT.isScript()) {
    // Gwt Dev can only access runtime level retention annotations
    assertHasAnno(testCase, annos, CompileRetention.class);
  }

  annos = ctor.getAnnotations();
  assertHasAnno(testCase, annos, RuntimeRetention.class);
  if (GWT.isScript()) {
    // Gwt Dev can only access runtime level retention annotations
    assertHasAnno(testCase, annos, CompileRetention.class);
  }

}
 
Example 14
Project: breakout   File: ObjectTreeTableModel.java View source code Vote up 6 votes
private static List<Field> getSortedFields(Class<?> type) {
	List<Field> result = new ArrayList<Field>();

	while (type != null) {
		for (Field field : type.getDeclaredFields()) {
			if (!Modifier.isStatic(field.getModifiers()) && !field.isSynthetic()) {
				result.add(field);
			}
		}
		type = type.getSuperclass();
	}

	Collections.sort(result, new FieldNameComparator());
	return result;
}
 
Example 15
Project: assertj-db   File: AbstractTest.java View source code Vote up 6 votes
@Before
public void initiate() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException,
        SecurityException {

  Field fieldLastSetup = DbSetupTracker.class.getDeclaredField("lastSetupLaunched");
  Field fieldNextLaunch = DbSetupTracker.class.getDeclaredField("nextLaunchSkipped");
  fieldLastSetup.setAccessible(true);
  fieldNextLaunch.setAccessible(true);
  Boolean nextLaunchSkipped = fieldNextLaunch.getBoolean(dbSetupTracker);
  DbSetup lastSetupLaunched = (DbSetup) fieldLastSetup.get(dbSetupTracker);
  boolean skipLaunch = nextLaunchSkipped && DB_SETUP.equals(lastSetupLaunched);
  LOG.warning("--------------------------------------------------");
  LOG.warning(getClass().getCanonicalName() + " - " + testNameRule.getMethodName() + " - skipLaunch : " + skipLaunch
              + " (" + nextLaunchSkipped + " && " + DB_SETUP.equals(lastSetupLaunched) + ")");
  LOG.warning("--------------------------------------------------");
  dbSetupTracker.launchIfNecessary(DB_SETUP);
}
 
Example 16
Project: gpu-garbage-collection   File: TestFieldReflection.java View source code Vote up 6 votes
private static void testDouble(final Object object, Field[] fields) {
  banner("double", "6.0");
  for (final Field field : fields) {
    try {
      field.setDouble(object, 6.0);
      changeSuccess();
    } catch (Exception e) { changeError(e); }
  }
  System.out.println();
}
 
Example 17
Project: slumdroid   File: Prefs.java View source code Vote up 6 votes
/**
 * Update value.
 *
 * @param parameter the parameter
 * @throws IllegalArgumentException the illegal argument exception
 * @throws IllegalAccessException the illegal access exception
 */
protected void updateValue(Field parameter) throws IllegalArgumentException, IllegalAccessException {
	Class<?> type = parameter.getType();
	if (type.equals(int.class)) {
		parameter.setInt(parameter, getInt(parameter));
	} else if (type.equals(long.class)) {
		parameter.setLong(parameter, getLong(parameter));
	} else if (type.equals(String.class)) {
		parameter.set(parameter, getString(parameter));
	} else if (type.equals(boolean.class)) {
		parameter.setBoolean(parameter, getBoolean(parameter));
	} else if (type.isArray()) {
		setArray(parameter, type);
	} else {
		return;
	}
}
 
Example 18
Project: xface-android   File: XInputScaleHandler.java View source code Vote up 6 votes
/**
 * ????WebView?mDefaultScale?xface??mOwnDefaulScale,???????Android2.3?????
 * @param scale
 * ????scale?
 */
public void setDefaultScaleForApiLevel10AndBelow(float defaultScale,
        WebView view) {
    try {
        Field mFieldDefaultScale = WebView.class
                .getDeclaredField("mDefaultScale");
        mFieldDefaultScale.setAccessible(true);
        mFieldDefaultScale.setFloat(view, defaultScale);
    } catch (Exception e) {
        XLog.e(CLASS_NAME, e.toString());
    }
}
 
Example 19
Project: gpu-garbage-collection   File: TestFieldReflection.java View source code Vote up 6 votes
private static void testShort(final Object object, final Field[] fields) {
  banner("short", "2");
  for (final Field field : fields) {
    try {
      field.setShort(object, (short) 2);
      changeSuccess();
    } catch (Exception e) { changeError(e); }
  }
  System.out.println();
}
 
Example 20
Project: MyFramework   File: Util.java View source code Vote up 6 votes
/**
 * Gets the address value for the memory that backs a direct byte buffer.
 * @param buffer
 * @return The system address for the buffers
 */
public static long getAddressFromDirectByteBuffer(ByteBuffer buffer)
{
    try
    {
        Field addressField = Buffer.class.getDeclaredField("address");
        addressField.setAccessible(true);
        return addressField.getLong(buffer);
    }
    catch (Exception e)
    {
        throw new RuntimeException("Unable to address field from ByteBuffer", e);
    }
}
 
Example 21
Project: gpu-garbage-collection   File: TestFieldReflection.java View source code Vote up 6 votes
private static void testByte(final Object object, final Field[] fields) {
  banner("byte", "12");
  for (final Field field : fields) {
    try {
      field.setByte(object, (byte) 12);
      changeSuccess();
    } catch (Exception e) { changeError(e); }
  }
  System.out.println();
}
 
Example 22
Project: JerseyTest   File: IntrospectionModeller.java View source code Vote up 6 votes
private static final void workOutFieldsList(
        AbstractResource resource, 
        boolean isEncoded) {        
    Class c = resource.getResourceClass();
    if (c.isInterface())
        return;
    
    while (c != Object.class) {
         for (final Field f : c.getDeclaredFields()) {
            if (f.getDeclaredAnnotations().length > 0) {
                final AbstractField af = new AbstractField(f);
                Parameter p = createParameter(
                        resource.getResourceClass(),
                        f.getDeclaringClass(),
                        isEncoded,
                        f.getType(),
                        f.getGenericType(),
                        f.getAnnotations());
                if (null != p) {
                    af.getParameters().add(p);
                    resource.getFields().add(af);
                }
            }
         }
         c = c.getSuperclass();
    }
}
 
Example 23
Project: ews-java-api   File: EwsUtilities.java View source code Vote up 6 votes
/**
 * Builds the schema to enum mapping dictionary.
 *
 * @param <E> Type of the enum.
 * @param c   Class
 * @return The mapping from enum to schema name
 */
private static <E extends Enum<E>> Map<String, String>
buildSchemaToEnumDict(Class<E> c) {
  Map<String, String> dict = new HashMap<String, String>();

  Field[] fields = c.getDeclaredFields();
  for (Field f : fields) {
    if (f.isEnumConstant() && f.isAnnotationPresent(EwsEnum.class)) {
      EwsEnum ewsEnum = f.getAnnotation(EwsEnum.class);
      String fieldName = f.getName();
      String schemaName = ewsEnum.schemaName();
      if (!schemaName.isEmpty()) {
        dict.put(schemaName, fieldName);
      }
    }
  }
  return dict;
}
 
Example 24
Project: katharsis-core   File: ResourceInformationBuilder.java View source code Vote up 6 votes
private <T> Set<Field> getBasicFields(Class<T> resourceClass, Field idField) {
    Set<Field> fields = new HashSet<>();
    for (Field field : resourceClass.getDeclaredFields()) {
        if (isBasicType(field.getType()) && !field.equals(idField)) {
            fields.add(field);
            if (isRestrictedMember(field.getName())) {
                throw new ResourceFieldException("Field " + field.getName() + " of class "
                        + resourceClass.getCanonicalName() + "is restricted");
            }
        }
    }
    return fields;
}
 
Example 25
Project: ecologylabFundamental   File: ByteType.java View source code Vote up 6 votes
/**
 * True if the value in the Field object matches the default value for this type.
 * 
 * @param field
 * @return
 */
@Override
public boolean isDefaultValue(Field field, Object context) 
   throws IllegalArgumentException, IllegalAccessException
   {
   	return field.getByte(context) == DEFAULT_VALUE;
   }
 
Example 26
Project: hrider   File: Clazz.java View source code Vote up 6 votes
/**
 * Gets a value of the field.
 *
 * @param obj   The instance which field's value is to be retrieved.
 * @param field The field that holds the value.
 * @return A value extracted from the field.
 * @throws IllegalAccessException Error accessing the field.
 */
public static Object getValue(Object obj, Field field) throws IllegalAccessException {
    field.setAccessible(true);

    String typeName = field.getType().getSimpleName();
    if ("int".equals(typeName) || "Integer".equals(typeName)) {
        return field.getInt(obj);
    }
    if ("long".equalsIgnoreCase(typeName)) {
        return field.getLong(obj);
    }
    if ("boolean".equalsIgnoreCase(typeName)) {
        return field.getBoolean(obj);
    }
    if ("byte".equalsIgnoreCase(typeName)) {
        return field.getByte(obj);
    }
    if ("char".equals(typeName) || "Character".equals(typeName)) {
        return field.getChar(obj);
    }
    if ("short".equalsIgnoreCase(typeName)) {
        return field.getShort(obj);
    }
    if ("float".equalsIgnoreCase(typeName)) {
        return field.getFloat(obj);
    }
    if ("double".equalsIgnoreCase(typeName)) {
        return field.getDouble(obj);
    }
    return field.get(obj);
}
 
Example 27
Project: ecologylabFundamental   File: CharType.java View source code Vote up 6 votes
/**
 * True if the value in the Field object matches the default value for this type.
 * 
 * @param field
 * @return
 */
@Override
public boolean isDefaultValue(Field field, Object context) throws IllegalArgumentException,
		IllegalAccessException
{
	return field.getChar(context) == DEFAULT_VALUE;
}
 
Example 28
Project: powerunit   File: RuleValidator.java View source code Vote up 6 votes
default void checkRuleAnnotationForField(Field f) {
    if (Modifier.isStatic(f.getModifiers())) {
        throw new InternalError("@Rule field is static " + f.toString());
    }
    if (!Modifier.isPublic(f.getModifiers())) {
        throw new InternalError("@Rule field is not public " + f.toString());
    }
    if (!Modifier.isFinal(f.getModifiers())) {
        throw new InternalError("@Rule field is not final " + f.toString());
    }
    if (!TestRule.class.isAssignableFrom(f.getType())) {
        throw new InternalError("@Rule field is not TestRule "
                + f.toString());
    }
}
 
Example 29
Project: FireflowEngine20   File: Mirror.java View source code Vote up 6 votes
/**
 * ??????????????????????????????
 * 
 * @param f
 *            ??
 * @return ??????
 */
public static Class<?>[] getGenericTypes(Field f) {
    String gts = f.toGenericString();
    Matcher m = PTN.matcher(gts);
    if (m.find()) {
        String s = m.group(2);
        String[] ss = Strings.splitIgnoreBlank(s);
        if (ss.length > 0) {
            Class<?>[] re = new Class<?>[ss.length];
            try {
                for (int i = 0; i < ss.length; i++) {
                    String className = ss[i];
                    if (className.length() > 0
                        && className.charAt(0) == '?')
                        re[i] = Object.class;
                    else {
                        int pos = className.indexOf('<');
                        if (pos < 0)
                            re[i] = Lang.loadClass(className);
                        else
                            re[i] = Lang.loadClass(className.substring(0,
                                                                       pos));
                    }
                }
                return re;
            }
            catch (ClassNotFoundException e) {
                throw Lang.wrapThrow(e);
            }
        }
    }
    return new Class<?>[0];
}
 
Example 30
Project: NucleusFramework   File: DataFieldSerializer.java View source code Vote up 5 votes
private static void setField(Field field, Object object, String keyName, IDataNode dataNode)
        throws IllegalAccessException {

    Class<?> clazz = field.getType();

    Object defaultValue = field.get(object);

    if (clazz.equals(boolean.class)) {
        field.setBoolean(object, dataNode.getBoolean(keyName));
    }
    else if (clazz.equals(byte.class)) {
        field.setByte(object, (byte) dataNode.getInteger(keyName));
    }
    else if (clazz.equals(short.class)) {
        field.setShort(object, (short) dataNode.getInteger(keyName));
    }
    else if (clazz.equals(char.class)) {
        field.setChar(object, (char) dataNode.getInteger(keyName));
    }
    else if (clazz.equals(int.class)) {
        field.setInt(object, dataNode.getInteger(keyName));
    }
    else if (clazz.equals(long.class)) {
        field.setLong(object, dataNode.getLong(keyName));
    }
    else if (clazz.equals(float.class)) {
        field.setFloat(object, (float) dataNode.getDouble(keyName));
    }
    else if (clazz.equals(double.class)) {
        field.setDouble(object, dataNode.getDouble(keyName));
    }
    else if (clazz.equals(String.class)) {
        field.set(object, dataNode.getString(keyName));
    }
    else if (clazz.isEnum()) {
        //noinspection unchecked
        field.set(object, dataNode.getEnumGeneric(keyName, null, (Class<? extends Enum<?>>)clazz));
    }
    else if (clazz.equals(Location.class)) {
        SyncLocation syncLocation = dataNode.getLocation(keyName);
        field.set(object, syncLocation != null ? syncLocation.getBukkitLocation() : (Location) defaultValue);
    }
    else if (clazz.equals(ItemStack.class)) {
        ItemStack[] stacks = dataNode.getItemStacks(keyName);
        field.set(object, stacks != null && stacks.length > 0 ? stacks[0] : null);
    }
    else if (clazz.equals(ItemStack[].class)) {
        field.set(object, dataNode.getItemStacks(keyName));
    }
    else if (IDataNodeSerializable.class.isAssignableFrom(clazz)) {
        //noinspection unchecked
        Object result = dataNode.getSerializable(keyName, (Class<? extends IDataNodeSerializable>)clazz);
        field.set(object, result);
    }
}
 
Example 31
Project: gpu-garbage-collection   File: BootImageWriter.java View source code Vote up 5 votes
/**
 * Write an object instantiating a class to the boot image
 * @param scalarImageAddress address already allocated for object
 * @param jdkObject object to write
 * @param jdkType java.lang.Class of object
 * @param rvmScalarType RVM class loader version of type
 * @param allocOnly allocate the object only?
 * @param overwriteAddress
 * @param parentObject
 * @param untraced
 * @return
 * @throws IllegalAccessException
 */
private static Address copyClassToBootImage(Address scalarImageAddress, Object jdkObject, Class<?> jdkType,
    RVMClass rvmScalarType, boolean allocOnly, Address overwriteAddress, Object parentObject, boolean  untraced)
throws IllegalAccessException {
  if (verbose >= 2) {
    if (depth == depthCutoff)
      say(SPACES.substring(0,depth+1), "TOO DEEP: cutting off");
    else if (depth < depthCutoff) {
      String tab = SPACES.substring(0,depth+1);
      if (depth == 0 && jtocCount >= 0)
        tab = tab + "jtoc #" + String.valueOf(jtocCount) + " ";
      int scalarSize = rvmScalarType.getInstanceSize();
      say(tab, "Copying object ", jdkType.getName(),
          "   size=", String.valueOf(scalarSize),
          (scalarSize >= LARGE_SCALAR_SIZE) ? " large object!!!" : "");
    }
  }

  // copy object fields from host jdk address space into image
  // recurse on values that are references
  RVMField[] rvmFields = rvmScalarType.getInstanceFields();
  for (int i = 0; i < rvmFields.length; ++i) {
    RVMField rvmField       = rvmFields[i];
    TypeReference rvmFieldType   = rvmField.getType();
    Address rvmFieldAddress = scalarImageAddress.plus(rvmField.getOffset());
    String  rvmFieldName    = rvmField.getName().toString();
    Field   jdkFieldAcc     = getJdkFieldAccessor(jdkType, i, INSTANCE_FIELD);

    boolean untracedField = rvmField.isUntraced() || untraced;

    if (jdkFieldAcc == null) {
      // Field not found via reflection
      if (!copyKnownInstanceField(jdkObject, rvmFieldName, rvmFieldType, rvmFieldAddress)) {
        // Field wasn't a known Classpath field so write null
        if (verbose >= 2) traceContext.push(rvmFieldType.toString(),
            jdkType.getName(), rvmFieldName);
        if (verbose >= 2) traceContext.traceFieldNotInHostJdk();
        if (verbose >= 2) traceContext.pop();
        if (rvmFieldType.isPrimitiveType()) {
          switch (rvmField.getType().getMemoryBytes()) {
          case 1: bootImage.setByte(rvmFieldAddress, 0);          break;
          case 2: bootImage.setHalfWord(rvmFieldAddress, 0);      break;
          case 4: bootImage.setFullWord(rvmFieldAddress, 0);      break;
          case 8: bootImage.setDoubleWord(rvmFieldAddress, 0L);   break;
          default:fail("unexpected field type: " + rvmFieldType); break;
          }
        } else {
          bootImage.setNullAddressWord(rvmFieldAddress, !untracedField, !untracedField, false);
        }
      }
      continue;
    }

    if (rvmFieldType.isPrimitiveType()) {
      // field is logical or numeric type
      if (rvmFieldType.isBooleanType()) {
        bootImage.setByte(rvmFieldAddress,
            jdkFieldAcc.getBoolean(jdkObject) ? 1 : 0);
      } else if (rvmFieldType.isByteType()) {
        bootImage.setByte(rvmFieldAddress,
            jdkFieldAcc.getByte(jdkObject));
      } else if (rvmFieldType.isCharType()) {
        bootImage.setHalfWord(rvmFieldAddress,
            jdkFieldAcc.getChar(jdkObject));
      } else if (rvmFieldType.isShortType()) {
        bootImage.setHalfWord(rvmFieldAddress,
            jdkFieldAcc.getShort(jdkObject));
      } else if (rvmFieldType.isIntType()) {
        try {
          bootImage.setFullWord(rvmFieldAddress, jdkFieldAcc.getInt(jdkObject));
        } catch (IllegalArgumentException ex) {
          // TODO: Harmony - clean this up
          if (jdkObject instanceof java.util.WeakHashMap && rvmFieldName.equals("loadFactor")) {
            // the field load factor field in Sun/Classpath is a float but
            // in Harmony it has been "optimized" to an int
            bootImage.setFullWord(rvmFieldAddress, 7500);
          } else if (jdkObject instanceof java.lang.ref.ReferenceQueue && rvmFieldName.equals("head")) {
            // Conflicting types between Harmony and Sun
            bootImage.setFullWord(rvmFieldAddress, 0);
          } else {
            System.out.println("type " + rvmScalarType + ", field " + rvmField);
            throw ex;
          }
        }
      } else if (rvmFieldType.isLongType()) {
        bootImage.setDoubleWord(rvmFieldAddress,
            jdkFieldAcc.getLong(jdkObject));
      } else if (rvmFieldType.isFloatType()) {
        float f = jdkFieldAcc.getFloat(jdkObject);
        bootImage.setFullWord(rvmFieldAddress,
            Float.floatToIntBits(f));
      } else if (rvmFieldType.isDoubleType()) {
        double d = jdkFieldAcc.getDouble(jdkObject);
        bootImage.setDoubleWord(rvmFieldAddress,
            Double.doubleToLongBits(d));
      } else if (rvmFieldType.equals(TypeReference.Address) ||
          rvmFieldType.equals(TypeReference.Word) ||
          rvmFieldType.equals(TypeReference.Extent) ||
          rvmFieldType.equals(TypeReference.Offset)) {
        Object o = jdkFieldAcc.get(jdkObject);
        String msg = " instance field " + rvmField.toString();
        boolean warn = rvmFieldType.equals(TypeReference.Address);
        bootImage.setAddressWord(rvmFieldAddress, getWordValue(o, msg, warn), false, false);
      } else {
        fail("unexpected primitive field type: " + rvmFieldType);
      }
    } else {
      // field is reference type
      Object value = jdkFieldAcc.get(jdkObject);
      if (!allocOnly) {
        Class<?> jdkClass = jdkFieldAcc.getDeclaringClass();
        if (verbose >= 2) traceContext.push(value.getClass().getName(),
            jdkClass.getName(),
            jdkFieldAcc.getName());
        copyReferenceFieldToBootImage(rvmFieldAddress, value, jdkObject,
            !untracedField, !(untracedField || rvmField.isFinal()), rvmFieldName, rvmFieldType);
      }
    }
  }
  return scalarImageAddress;
}