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

Ignore interface/class without default constructs fields in SB config #30947

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,7 @@ private ResultHandle populateConfigObject(ClassLoader classLoader, ClassInfo con
break;
}
}
} else {
if (!fieldTypeClassInfo.hasNoArgsConstructor()) {
throw new IllegalArgumentException(
"Nested configuration class '" + fieldTypeClassInfo
+ "' must contain a no-args constructor ");
}

} else if (fieldTypeClassInfo.hasNoArgsConstructor()) {
if (!Modifier.isPublic(fieldTypeClassInfo.flags())) {
throw new IllegalArgumentException(
"Nested configuration class '" + fieldTypeClassInfo + "' must be public ");
Expand All @@ -325,6 +319,10 @@ private ResultHandle populateConfigObject(ClassLoader classLoader, ClassInfo con
getFullConfigName(prefixStr, namingStrategy, field), namingStrategy, failOnMismatchingMember,
null, methodCreator);
createWriteValue(methodCreator, configObject, field, setter, useFieldAccess, nestedConfigObject);
} else {
LOGGER.warn("Nested configuration class '" + fieldTypeClassInfo
+ "' declared in '" + currentClassInHierarchy.name() + "." + field.name() + "' is either an "
+ "interface or does not have a non-args constructor, so this field will not be initialized");
}
} else {
String fullConfigName = getFullConfigName(prefixStr, namingStrategy, field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public final class ClassProperties {

private AnotherClass anotherClass;

private Interface anInterface;

public String getValue() {
return value;
}
Expand All @@ -24,4 +26,12 @@ public AnotherClass getAnotherClass() {
public void setAnotherClass(AnotherClass anotherClass) {
this.anotherClass = anotherClass;
}

public Interface getAnInterface() {
return anInterface;
}

public void setAnInterface(Interface anInterface) {
this.anInterface = anInterface;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public String getValue() {
public boolean isAnotherClassValue() {
return properties.getAnotherClass().isValue();
}

@Path("/interface")
@GET
public boolean getUrlFromClassWithInterface() {
return properties.getAnInterface() == null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.quarkus.it.spring.boot;

public interface Interface {
String getUrl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ cl.value=class-value
cl.another-class.value=true
bean.value=1
bean.inner-class.value=inner-class-value
interface.value=interface-value
interface.value=interface-value
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ void shouldHaveAnotherClassValue() {
.then()
.body(is(equalTo("true")));
}

@Test
void shouldInterfaceNotBePopulated() {
when().get("/class/interface")
.then()
.body(is(equalTo("true")));
}
}