int lookupResourceValue(Ref<Res_value> value) {
    byte resolvedType = DataType.REFERENCE.code();
    Res_value inValue = value.get();

    DataType dataType;
    try {
      dataType = DataType.fromCode(inValue.dataType);
    } catch (IllegalArgumentException e) {
      return BAD_TYPE;
    }

    switch (dataType) {
      case ATTRIBUTE:
        resolvedType = DataType.ATTRIBUTE.code();
      // fallthrough
      case REFERENCE:
        if (!mAppAsLib) {
          return NO_ERROR;
        }

        // If the package is loaded as shared library, the resource reference
        // also need to be fixed.
        break;
      case DYNAMIC_ATTRIBUTE:
        resolvedType = DataType.ATTRIBUTE.code();
      // fallthrough
      case DYNAMIC_REFERENCE:
        break;
      default:
        return NO_ERROR;
    }

    final Ref<Integer> resIdRef = new Ref<>(inValue.data);
    int err = lookupResourceId(resIdRef);
    value.set(inValue.withData(resIdRef.get()));
    if (err != NO_ERROR) {
      return err;
    }

    value.set(new Res_value(resolvedType, resIdRef.get()));
    return NO_ERROR;
  }
@Test
  public void lookupResourceValue_returnsBadTypeIfTypeOutOfEnumRange() {
    DynamicRefTable pseudoRefTable =
        new DynamicRefTable(/* packageId= */ (byte) 0, /* appAsLib= */ true);
    assertThat(pseudoRefTable.lookupResourceValue(RES_VALUE_OF_BAD_TYPE)).isEqualTo(BAD_TYPE);
  }