-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid classes with incomplete hierarchy in Hibernate Validator
- Loading branch information
Showing
2 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ator/deployment/src/test/java/io/quarkus/hibernate/validator/test/ClassHierarchyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.quarkus.hibernate.validator.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.AbstractCollection; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.Validator; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import net.bytebuddy.ByteBuddy; | ||
import net.bytebuddy.dynamic.DynamicType; | ||
|
||
public class ClassHierarchyTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(() -> ShrinkWrap | ||
.create(JavaArchive.class) | ||
.add(new ByteArrayAsset(createClassWithIncompleteHierarchy()), "InnerClass.class") | ||
.addClass(Dto.class)); | ||
|
||
private static byte[] createClassWithIncompleteHierarchy() { | ||
// Create an inner class with an incomplete hierarchy | ||
try (DynamicType.Unloaded<?> superClass = new ByteBuddy() | ||
.subclass(Object.class) | ||
.name("SuperClass") | ||
.make(); | ||
DynamicType.Unloaded<?> outerClass = new ByteBuddy() | ||
.subclass(superClass.getTypeDescription()) | ||
.name("OuterClass") | ||
.make(); | ||
DynamicType.Unloaded<?> innerClass = new ByteBuddy() | ||
.subclass(AbstractCollection.class) | ||
.innerTypeOf(outerClass.getTypeDescription()) | ||
.name("InnerClass") | ||
.make(); | ||
DynamicType.Loaded<?> load = innerClass.load(Thread.currentThread().getContextClassLoader())) { | ||
return load.getBytes(); | ||
} | ||
} | ||
|
||
@Inject | ||
Validator validator; | ||
|
||
@Test | ||
public void doNotFailWhenLoadingIncompleteClassHierarchy() { | ||
assertThat(validator).isNotNull(); | ||
} | ||
|
||
@Valid | ||
public static class Dto { | ||
String name; | ||
|
||
// XMLBean.ErrorLogger is a subclass with an incomplete hierarchy | ||
@Valid | ||
AbstractCollection<String> items; | ||
} | ||
} |