-
Notifications
You must be signed in to change notification settings - Fork 162
feat: add mutator support for generic classes #1008
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
base: main
Are you sure you want to change the base?
Conversation
f119aa8 to
581c4d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for generic classes in the mutator framework by resolving type parameters at runtime. Previously, generic classes would fail to create valid mutators due to type erasure causing parameter and return types to be reported as java.lang.Object. The implementation uses AnnotatedType to resolve type parameters and construct mutators with the correct concrete types.
Key Changes:
- Added type resolution logic to handle generic type parameters in constructors, methods, and return types
- Updated all aggregate mutator factories to resolve generic types before creating mutators
- Added comprehensive test coverage for generic classes across different mutator types (setter-based, constructor-based, cached, records)
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| BeanSupport.java | Adds core type resolution methods for resolving generic type arguments in methods, constructors, and return types |
| AggregatesHelper.java | Updates mutator creation to use resolved types instead of raw types from reflection API |
| CachedConstructorMutatorFactory.java | Uses resolved parameter types when building mutators for generic classes |
| ConstructorBasedBeanMutatorFactory.java | Resolves parameter types and return types when matching getters to constructors |
| SetterBasedBeanMutatorFactory.java | Resolves setter parameter types to properly handle generic classes |
| SuperBuilderMutatorFactory.java | Updates to use resolved parameter types for builder pattern support |
| SetterBasedBeanMutatorTest.java | Adds test for generic class with setter-based mutation |
| RecordMutatorTest.java | Adds test for generic record types |
| ConstructorBasedBeanMutatorTest.java | Adds tests for generic classes with single and nested type parameters |
| CachedConstructorMutatorTest.java | Adds test for generic class with cached constructor |
| StressTest.java | Adds stress test cases for various generic class patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/com/code_intelligence/jazzer/mutation/mutator/aggregate/BeanSupport.java
Show resolved
Hide resolved
src/main/java/com/code_intelligence/jazzer/mutation/mutator/aggregate/BeanSupport.java
Outdated
Show resolved
Hide resolved
src/main/java/com/code_intelligence/jazzer/mutation/mutator/aggregate/AggregatesHelper.java
Show resolved
Hide resolved
581c4d5 to
08f6331
Compare
08f6331 to
a9ae722
Compare
Adds mutator support for generic classes.
Constructing mutators for generic classes would previously either fail or not work as expected due to parameter and return types being reported as
java.lang.Objectby the reflection API (type erasure). Since we can't provide a generalObjectmutator this would creation of a valid mutator for most generic classes.Using the
AnnotatedTypeof the class we resolve type parameters to create the correct underlying mutators.Example fuzz test: