Skip to content

Fix for ebean-gradle-plugin issue #43#234

Merged
rbygrave merged 1 commit into
masterfrom
feature/kotlin-gradle-detect
Jun 19, 2026
Merged

Fix for ebean-gradle-plugin issue #43#234
rbygrave merged 1 commit into
masterfrom
feature/kotlin-gradle-detect

Conversation

@rob-bygrave

Copy link
Copy Markdown
Contributor

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

  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
@rbygrave rbygrave self-assigned this Jun 19, 2026
@rbygrave rbygrave added this to the 16.11.1 milestone Jun 19, 2026
@rbygrave rbygrave merged commit 5c5542b into master Jun 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants