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

Avoid warnings from JDK 11 when looking up injectable fields #34

Merged
merged 1 commit into from
May 17, 2023
Merged
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
15 changes: 10 additions & 5 deletions sisu/src/main/java/io/smallrye/beanbag/sisu/Sisu.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ private <T> void addBeanFromXml(final Class<T> clazz, final Class<?> type, final

Map<String, Field> injectableFields = new HashMap<>();
for (Class<?> cur = clazz; cur != null; cur = cur.getSuperclass()) {
Module module = cur.getModule();
if (!module.isOpen(cur.getPackageName(), Sisu.class.getModule())) {
// skip fields of this class because we are not permitted to access them
continue;
}
Field[] declaredFields = cur.getDeclaredFields();
for (Field declaredField : declaredFields) {
int mods = declaredField.getModifiers();
Expand Down Expand Up @@ -716,7 +721,9 @@ private static <T> void addFieldInjections(final Class<? super T> clazz, final B
if (!fieldAnnotations.isInject()) {
continue;
}
field.setAccessible(true);
if (!field.trySetAccessible()) {
continue;
}
boolean optional = fieldAnnotations.isNullable();
final String paramNamed = fieldAnnotations.getNamed();
final String name = paramNamed == null ? "" : paramNamed;
Expand Down Expand Up @@ -776,15 +783,13 @@ private static <T> Constructor<T> findConstructor(Class<T> clazz) {
throw new RuntimeException("Cannot get declared constructors from " + clazz, t);
}
for (Constructor<?> constructor : declaredConstructors) {
if (Annotations.of(constructor).isInject()) {
constructor.setAccessible(true);
if (Annotations.of(constructor).isInject() && constructor.trySetAccessible()) {
return (Constructor<T>) constructor;
} else if (constructor.getParameterCount() == 0) {
defaultConstructor = (Constructor<T>) constructor;
}
}
if (defaultConstructor != null) {
defaultConstructor.setAccessible(true);
if (defaultConstructor != null && defaultConstructor.trySetAccessible()) {
return defaultConstructor;
}
throw new RuntimeException("No valid constructor found on " + clazz);
Expand Down