Skip to content

Modify it to avoid adding runtimeHints for primitive types and array types. #3284

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -41,6 +41,10 @@ public static void contributeEntityPath(Class<?> type, GenerationContext context
return;
}

if (type.isPrimitive() || type.isArray()) {
return;
}

String queryClassName = getQueryClassName(type);
if (ClassUtils.isPresent(queryClassName, classLoader)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@
import org.springframework.data.aot.sample.ConfigWithQuerydslPredicateExecutor.Person;
import org.springframework.data.aot.sample.QConfigWithQuerydslPredicateExecutor_Person;
import org.springframework.data.classloadersupport.HidingClassLoader;
import org.springframework.data.querydsl.User;
import org.springframework.javapoet.ClassName;

import com.querydsl.core.types.EntityPath;

/**
* Unit tests for {@link QTypeContributor}.
*
* @author ckdgus08
*/
class QTypeContributorUnitTests {

@Test // GH-2721
Expand Down Expand Up @@ -68,4 +74,59 @@ void doesNotAddQTypeHintIfQuerydslNotPresent() {
assertThat(generationContext.getRuntimeHints()).matches(
RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person.class).negate());
}

@Test // DATAMONGO-4958
void doesNotAddQTypeHintForArrayType() {

GenerationContext generationContext = new DefaultGenerationContext(
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles());

QTypeContributor.contributeEntityPath(Person[].class, generationContext, HidingClassLoader.hideTypes());

assertThat(generationContext.getRuntimeHints()).matches(
RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person.class).negate());
assertThat(generationContext.getRuntimeHints()).matches(
RuntimeHintsPredicates.reflection().onType(QConfigWithQuerydslPredicateExecutor_Person[].class).negate());
}

@Test // DATAMONGO-4958
void addsQTypeHintForQUserType() {

GenerationContext generationContext = new DefaultGenerationContext(
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles());

QTypeContributor.contributeEntityPath(User.class, generationContext, getClass().getClassLoader());

var qUserHintCount = generationContext.getRuntimeHints().reflection().typeHints()
.filter(hint -> hint.getType().getName().equals("org.springframework.data.querydsl.QUser"))
.count();
assertThat(qUserHintCount).isEqualTo(1);
}

@Test // DATAMONGO-4958
void doesNotAddQTypeHintForQUserArrayType() {

GenerationContext generationContext = new DefaultGenerationContext(
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles());
var classLoader = getClass().getClassLoader();

QTypeContributor.contributeEntityPath(User[].class, generationContext, classLoader);

assertThat(generationContext.getRuntimeHints().reflection().typeHints()).isEmpty();
var qUserHintCount = generationContext.getRuntimeHints().reflection().typeHints()
.filter(hint -> hint.getType().getName().equals("org.springframework.data.querydsl.QUser"))
.count();
assertThat(qUserHintCount).isEqualTo(0);
}

@Test // DATAMONGO-4958
void doesNotAddQTypeHintForPrimitiveType() {

GenerationContext generationContext = new DefaultGenerationContext(
new ClassNameGenerator(ClassName.get(this.getClass())), new InMemoryGeneratedFiles());

QTypeContributor.contributeEntityPath(int.class, generationContext, getClass().getClassLoader());

assertThat(generationContext.getRuntimeHints().reflection().typeHints()).isEmpty();
}
}