Improvement/reflection and performance fixes#658
Merged
Conversation
#2 - ThreadLocal<Object> → ThreadLocal<Deque<Object>> for rootSourceStack. Explicit push/pop in finally blocks replaces the old set/remove pattern. Semantics are unchanged (isRoot = stack.isEmpty()); the Deque structure documents the call-stack nature and prepares for future re-entrancy fixes. Comment explains the current limitation for FieldTransformer callbacks. #3 - EffectiveSource private inner class replaced with a Java record. Eliminates boilerplate constructor/field declarations; immutability is enforced by the language. #4 - Removed confusing dead variable `K k = null` in getConstructorValuesFromFields. null is passed directly, making intent obvious. #5 - Added @slf4j (SLF4J promoted from test to compile scope) and a DEBUG log in getSourceFieldValue when a field is missing but a transformer is defined. This makes previously silent null propagation into transformers visible. #7 - AbstractBeanTransformerTest.beforeMethod() consolidated: replaced three individual reset calls with underTest.reset() + underTest.resetFieldsTransformer(). reset() atomically replaces all settings; resetFieldsTransformer() additionally clears the shared static CacheManager entries that reset() does not touch. #8 - Populator: ReflectionUtils and ClassUtils are stateless (all state in static caches. Two private static final singletons back the instance fields, so PopulatorFactory no longer allocates fresh utility instances per field transformation. #9 - Fixed ineffective null caching in three methods: * getDestFieldName: ABSENT_FIELD_NAME (0) sentinel avoids a cache miss on every call when a constructor parameter has no compiled name and no @ConstructorArg annotation. * getSourceFieldType: AbsentFieldType sentinel class avoids a cache miss when a source field is absent and default-value mode is active. * getPrimitiveTypeTransformer: NO_OP_FIELD_TRANSFORMER_SENTINEL (identity FieldTransformer) avoids a cache miss when no type conversion is needed. #11 - getConstructorArgsValues: replaced side-effectful IntStream.forEach + pre-allocated array with IntStream.mapToObj().toArray(). The stream now owns index ordering, making it safe to enable .parallel() in the future without introducing data races. EOF )
- Replace NO_OP_FIELD_TRANSFORMER_SENTINEL (FieldTransformer with an unreachable lambda body) with a two-key cache approach in getPrimitiveTypeTransformer: a Boolean.TRUE marker stored under cacheKey + ".nullConversion" represents a cached null result, eliminating the uncoverable lambda$static$0 method. - Add testResetFieldsTransformationSkipWorksProperly to cover the previously uncalled resetFieldsTransformationSkip() method. - Add testGetSourceFieldTypeReturnsCachedNullForAbsentField to cover the ABSENT_SOURCE_FIELD_TYPE sentinel cache-hit branch. - Add testGetDestFieldNameReturnsCachedNullForParameterWithNoAnnotation to cover the ABSENT_FIELD_NAME sentinel cache-hit branch. - Add testAutomaticPrimitiveTypeTransformationCachesNullConversionForSameTypeFields to cover the null-marker cache-hit branch in getPrimitiveTypeTransformer. - Add testCanBeInjectedByConstructorParamsLambdaBranchesWorkCorrectly to cover the areNamesAvailable=false branches of the || expression inside canBeInjectedByConstructorParams lambda. All JaCoCo coverage checks now pass (methods=1.0, branches, lines, etc.).
Raise all JaCoCo coverage ratios to 1.0 (instructions, branches, complexity, lines, methods, classes) and add the tests required to achieve full branch coverage across bull-common and bull-bean-transformer. bull-common / ClassUtilsTest: - Cover isSynthetic() true branch via lambda (hidden/synthetic class) - Cover isPrimitiveTypeArray false branch (non-array class) - Cover getDefaultTypeValue false branch (non-primitive type) - Cover isSpecialType enum branch via ClassType enum - Cover getPrivateFields null-superclass and static-field branches - Cover getConcreteClass non-interface field branch - Cover hasFinalFields null-superclass branch - Cover getInstance happy-path branch - Add proxy import → lambda approach for synthetic class bull-common / ReflectionUtilsTest: - Cover isGetter/isSetter edge cases (void return, non-void return, params) - Cover getGenericFieldType non-parameterised field → null branch - Cover getMapGenericType wildcard and complex-map branches - Cover getGenericClassType empty type-arguments branch (via reflection) - Cover getArgumentTypeClass List-instance branch and non-WildcardType path - Cover getFieldValue "class" fallback to getter method bull-common / MutableToFooAdvFields: - Add setFluent() (non-void setter) and getNone() (void getter-like method) to enable edge-case branch coverage in isSetter/isGetter bull-bean-transformer / MutableObjectTransformationTest: - Add testSkipTransformationForFieldWithNoArgsDoesNothing (empty varargs) - Replace null-marker cache test to use a source missing a primitive field with setDefaultValueForMissingField=true, so the null-marker is actually stored and retrieved on the second transform call bull-bean-transformer / BeanTransformerTest: - Add testResolveEffectiveSourceWithMappingAndEmptyStackFallsThrough: covers mapped!=null && stack.isEmpty() false branch via reflection - Add testVoidTransformWithPrePopulatedStackDoesNotPushAgain: covers isRoot=false branches in void transform(T,K,String) via pre-populating the ThreadLocal stack with reflection bull-bean-transformer / PopulatorFactoryTest: - Add testGetPopulatorReturnsOptionalPopulatorWhenOnlyDestIsOptional: covers source!=Optional, dest==Optional branch bull-bean-transformer / ArrayPopulatorTest: - Add Object[] test cases for isPrimitiveTypeArray=false+isPrimitiveOrSpecialType=true and for lambda TRUE branch (primitive element in Object array) bull-bean-transformer / CollectionPopulatorTest (new): - Add direct unit test for CollectionPopulator covering toSet() branch when fieldType is Set
Add testAutomaticPrimitiveTypeTransformerCacheHitOnSecondTransform to cover the fromCache.isPresent() == true branch (lines 696-697) by transforming fromFooPrimitiveTypes twice in the same test, so the second call hits the cached FieldTransformer.
…e coverage
Add ImmutableToFooWithStaticField sample class (non-static final field +
static non-final field) and two new DataProvider entries in ClassUtilsTest:
- dataGetPrivateFinalFieldsTesting: add CLASS_WITH_STATIC_FIELDS (expected=0)
→ IS_FINAL_AND_NOT_STATIC_FIELD evaluates isFinal=true/isStatic=true → false
- dataGetClassTypeTesting: add ImmutableToFooWithStaticField (expected=IMMUTABLE)
→ hasNotFinalFields scans the static non-final field, evaluating
!isFinal=true/!isStatic=false → false (second && operand now exercised)
These two missing branches were the only gap preventing 100% in the
jacoco:report-aggregate output (Branches 490/492, Complexity 784/786).
Test Coverage Report
|
Replace the two-column (% | count) layout with a single combined cell showing '100.00% (492/492)' for both Baseline and Build, and drop the now-redundant empty header columns.
…ment" This reverts commit 82e86e1.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
bull-bean-transformer/pom.xml
Populator.java
TransformerImpl.java
Test improvements
How Has This Been Tested?
Checklist:
feature: Feature I'm adding or expandingbug: Bugfix or experimentwip: Work in progress; stuff I know won't be finished soon