Skip to content

Commit

Permalink
allow exception to be attached to UnresolvedJava/Type/Method/Field
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Dec 16, 2024
1 parent 45a3297 commit 0127c1c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,10 @@ public JavaField lookupField(int rawIndex, ResolvedJavaMethod method, int opcode
HotSpotResolvedObjectTypeImpl resolvedHolder;
try {
resolvedHolder = compilerToVM().resolveFieldInPool(this, rawIndex, (HotSpotResolvedJavaMethodImpl) method, (byte) opcode, info);
} catch (Throwable t) {
resolvedHolder = null;
} catch (Throwable cause) {
return new UnresolvedJavaField(fieldHolder, lookupUtf8(getNameRefIndexAt(nameAndTypeIndex)), type, cause);
}
if (resolvedHolder == null) {
// There was an exception resolving the field or it returned null so return an unresolved field.
return new UnresolvedJavaField(fieldHolder, lookupUtf8(getNameRefIndexAt(nameAndTypeIndex)), type);
}
final int flags = info[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,10 +31,27 @@ public final class UnresolvedJavaField implements JavaField {
private final JavaType holder;
private final JavaType type;

public UnresolvedJavaField(JavaType holder, String name, JavaType type) {
/**
* The reason method resolution failed. Can be null.
*/
private final Throwable cause;

public UnresolvedJavaField(JavaType holder, String name, JavaType type, Throwable cause) {
this.name = name;
this.type = type;
this.holder = holder;
this.cause = cause;
}

public UnresolvedJavaField(JavaType holder, String name, JavaType type) {
this(holder, name, type, null);
}

/**
* Gets the exception, if any, representing the reason field resolution resulted in this object.
*/
public Throwable getCause() {
return cause;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,10 +31,27 @@ public final class UnresolvedJavaMethod implements JavaMethod {
private final Signature signature;
protected JavaType holder;

public UnresolvedJavaMethod(String name, Signature signature, JavaType holder) {
/**
* The reason method resolution failed. Can be null.
*/
private final Throwable cause;

public UnresolvedJavaMethod(String name, Signature signature, JavaType holder, Throwable cause) {
this.name = name;
this.holder = holder;
this.signature = signature;
this.cause = cause;
}

public UnresolvedJavaMethod(String name, Signature signature, JavaType holder) {
this(name, signature, holder, null);
}

/**
* Gets the exception, if any, representing the reason method resolution resulted in this object.
*/
public Throwable getCause() {
return cause;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,34 +28,54 @@
public final class UnresolvedJavaType implements JavaType {
private final String name;

/**
* The reason type resolution failed. Can be null.
*/
private final Throwable cause;

@Override
public String getName() {
return name;
}

private UnresolvedJavaType(String name) {
private UnresolvedJavaType(String name, Throwable cause) {
this.name = name;
this.cause = cause;
assert name.length() == 1 && JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0)) != null || name.charAt(0) == '[' || name.charAt(name.length() - 1) == ';' : name;
}

/**
* Creates an unresolved type for a valid {@link JavaType#getName() type name}.
*/
public static UnresolvedJavaType create(String name) {
return new UnresolvedJavaType(name);
return new UnresolvedJavaType(name, null);
}

/**
* Creates an unresolved type for a valid {@link JavaType#getName() type name}.
*/
public static UnresolvedJavaType create(String name, Throwable cause) {
return new UnresolvedJavaType(name, cause);
}

/**
* Gets the exception, if any, representing the reason type resolution resulted in this object.
*/
public Throwable getCause() {
return cause;
}

@Override
public JavaType getComponentType() {
if (getName().charAt(0) == '[') {
return new UnresolvedJavaType(getName().substring(1));
return new UnresolvedJavaType(getName().substring(1), null);
}
return null;
}

@Override
public JavaType getArrayClass() {
return new UnresolvedJavaType('[' + getName());
return new UnresolvedJavaType('[' + getName(), null);
}

@Override
Expand Down

0 comments on commit 0127c1c

Please sign in to comment.