Fix for ebean-gradle-plugin issue #43#234
Merged
Merged
Conversation
Root Cause The regression from 16.4.0 → 16.5.0+ is in ebean-agent, not the plugin code itself. What changed: The new EbeanEnhanceTask (introduced via PR #41) captures sourceSet.output.classesDirs at Gradle configuration time (afterEvaluate). The Kotlin kapt plugin may not have registered its output directory — which contains META-INF/ebean-generated-info.mf — into classesDirs at that point. The old plugin (16.4.0) evaluated classesDirs inside a doLast hook at task execution time, when all kapt outputs were already registered. Effect (chain of failures): 1. AgentManifest can't find ebean-generated-info.mf → entityPackages is empty 2. DetectQueryBean.isQueryBean("QRoleEntity") iterates empty entityPackages → returns false 3. AgentManifest.isDetectQueryBean("QRoleEntity") → false 4. EnhanceContext.isQueryBean() returns false immediately (the null-fallback is unreachable) 5. MethodAdapter does not replace GETFIELD permissions with _permissions() 6. Original Kotlin getter body runs → null-check on uninitialised lateinit field → UninitializedPropertyAccessException Fix File: ebean-agent/src/main/java/io/ebean/enhance/querybean/DetectQueryBean.java Added an empty-packages fallback in isQueryBean(): when entityPackages is empty (manifest not found), trust naming convention alone — any class in a .../query/Q... or .../query/assoc/Q... package is treated as a query bean. This is consistent with FilterQueryBean.detectOnAll which already applies the same logic. With the fix: - manifest.isDetectQueryBean("QRoleEntity") → true (naming convention match) - reader.get(true, owner, classLoader) reads bytes from enhancedDir - classMeta.isQueryBean() → true (@TypeQueryBean annotation present) - GETFIELD is replaced by _permissions() → enhancement works correctly
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.
Root Cause
The regression from 16.4.0 → 16.5.0+ is in ebean-agent, not the plugin code itself.
What changed: The new EbeanEnhanceTask (introduced via PR #41) captures sourceSet.output.classesDirs at Gradle configuration time (afterEvaluate). The Kotlin kapt plugin may not have registered its output directory — which contains META-INF/ebean-generated-info.mf — into classesDirs at that point. The old plugin (16.4.0) evaluated classesDirs inside a doLast hook at task execution time, when all kapt outputs were already registered.
Effect (chain of failures):
Fix
File: ebean-agent/src/main/java/io/ebean/enhance/querybean/DetectQueryBean.java
Added an empty-packages fallback in isQueryBean(): when entityPackages is empty (manifest not found), trust naming convention alone — any class in a .../query/Q... or .../query/assoc/Q... package is treated as a query bean. This is consistent with FilterQueryBean.detectOnAll which already applies the same logic.
With the fix: