Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include meaningful diagnostics when getDeclaredFields/getDeclaredMethods fails due to linkage errors #1283

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions core/src/com/google/inject/spi/InjectionPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ private static Set<InjectionPoint> getInjectionPoints(

TypeLiteral<?> current = hierarchy.get(i);

for (Field field : getDeclaredFields(current)) {
for (Field field : getDeclaredFields(current, errors)) {
if (Modifier.isStatic(field.getModifiers()) == statics) {
Annotation atInject = getAtInject(field);
if (atInject != null) {
Expand All @@ -673,7 +673,7 @@ private static Set<InjectionPoint> getInjectionPoints(
}
}

for (Method method : getDeclaredMethods(current)) {
for (Method method : getDeclaredMethods(current, errors)) {
if (isEligibleForInjection(method, statics)) {
Annotation atInject = getAtInject(method);
if (atInject != null) {
Expand Down Expand Up @@ -749,12 +749,22 @@ private static Set<InjectionPoint> getInjectionPoints(
return builder.build();
}

private static Field[] getDeclaredFields(TypeLiteral<?> type) {
return DeclaredMembers.getDeclaredFields(type.getRawType());
private static Field[] getDeclaredFields(TypeLiteral<?> type, Errors errors) {
try {
return DeclaredMembers.getDeclaredFields(type.getRawType());
} catch (Throwable x) {
errors.errorInUserCode(x, "Failed to inspect fields in %s", type);
return new Field[0];
}
}

private static Method[] getDeclaredMethods(TypeLiteral<?> type) {
return DeclaredMembers.getDeclaredMethods(type.getRawType());
private static Method[] getDeclaredMethods(TypeLiteral<?> type, Errors errors) {
try {
return DeclaredMembers.getDeclaredMethods(type.getRawType());
} catch (Throwable x) {
errors.errorInUserCode(x, "Failed to inspect methods in %s", type);
return new Method[0];
}
}

/**
Expand Down