Add a direct sub classes data structure to the Painless lookup (#76955)#9
Add a direct sub classes data structure to the Painless lookup (#76955)#9MitchLewis930 wants to merge 2 commits intopr_019_beforefrom
Conversation
…ic#76955) This change has two main components. The first is to have method/field resolution for compile-time and run-time use the same code path for now. This removes copying of member methods between super and sub classes and instead does a resolution through the class hierarchy. This allows us to correctly implement the next change. The second is a data structure that allows for the lookup of direct sub classes for all allow listed classes/interfaces within Painless.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
|
|
||
| if (painlessObject != null) { | ||
| return painlessObject; | ||
| targetInterfaces.addAll(Arrays.asList(targetInterface.getInterfaces())); |
There was a problem hiding this comment.
Interface traversal skips non-whitelisted intermediate interfaces
High Severity
The lookupPainlessObject method only adds parent interfaces to the search queue when the current interface is in the whitelist (targetPainlessClass != null). When an interface is NOT whitelisted, its parent interfaces are never searched. This is inconsistent with buildPainlessClassHierarchy which correctly continues traversing parent interfaces when an intermediate interface is not whitelisted (via the else branch). Methods and fields on whitelisted interfaces that are only reachable through non-whitelisted intermediate interfaces will fail to be found at lookup time.
...les/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java
Show resolved
Hide resolved
Co-authored-by: MitchLewis930 <MitchLewis930@users.noreply.github.com>


PR_019
Note
Medium Risk
Changes core Painless symbol-resolution logic (methods/fields/runtime handles and functional-interface detection), which could affect script compilation or runtime behavior in edge cases, though covered by new targeted tests.
Overview
Adds a new
classesToDirectSubClassesindex toPainlessLookup, built during lookup construction, and exposes it viagetDirectSubClassesfor navigating the allow-listed type hierarchy (including handling gaps in the whitelist and interface relationships).Refactors member/method resolution to use a shared
lookupPainlessObjectthat walks superclasses and transitively walks interfaces (with de-duping), including anObjectfallback for interface targets; functional-interface method selection is updated to also resolve inherited SAM methods, with new tests and a dedicated whitelist resource covering these cases.Written by Cursor Bugbot for commit 2a11f7e. This will update automatically on new commits. Configure here.