Skip to content

Conversation

raphw
Copy link
Member

@raphw raphw commented Aug 17, 2025

Avoids using the system loader on Graal, by always choosing an "expen…sive" class loadings strategy, if a Graal image code is discovered. In the compiled artifact, this will anyways not effectuate, so that this is not a problem on Graal when only affecting training runs.

…sive" class loadings strategy, if a Graal image code is discovered. In the compiled artifact, this will anyways not effectuate, so that this is not a problem on Graal when only affecting training runs.
@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.40%. Comparing base (144751b) to head (81f0eb7).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
.../creation/bytebuddy/SubclassBytecodeGenerator.java 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3710      +/-   ##
============================================
- Coverage     86.43%   86.40%   -0.04%     
  Complexity     2969     2969              
============================================
  Files           341      341              
  Lines          9011     9013       +2     
  Branches       1110     1111       +1     
============================================
- Hits           7789     7788       -1     
- Misses          941      943       +2     
- Partials        281      282       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TimvdLippe
Copy link
Contributor

The fix seems fine to me, but I don't feel comfortable merging these fixes without Graal tests. Can we invest some time in adding Graal tests so we can catch such regressions?

@raphw
Copy link
Member Author

raphw commented Aug 17, 2025

We would need Graal with similar parameters: https://github.com/aws-powertools/powertools-lambda-java/blob/7e9ff02ea344ceeb0c9aa2b9736d28532085726a/powertools-common/pom.xml#L108

And then inspect the generated JSON to contain a reference to a mock class with the given name.

@phipag
Copy link
Contributor

phipag commented Aug 18, 2025

Thanks @raphw, for sending this PR. Let me test this in my project and see if it works.

The fix seems fine to me, but I don't feel comfortable merging these fixes without Graal tests. Can we invest some time in adding Graal tests so we can catch such regressions?

As a matter of fact, in my project I caught this regression by adding Graal native tests to our CI/CD pipeline (WIP: aws-powertools/powertools-lambda-java#2047) on GitHub actions. They used to work, but we never ran them as part of an automation which is why I only caught the problem now and not earlier.

@phipag
Copy link
Contributor

phipag commented Aug 18, 2025

I just tested this PR against my minimal example and it fixes the problem.

The Mocks are correctly included in predefined-classes-config.json:

[
  {
    "type":"agent-extracted",
    "classes":[
      { "nameInfo":"org/mockito/internal/creation/bytebuddy/codegen/MessageClass$MockitoMock$2htoda0op99200N$auxiliary$4cscpe1S", "hash":"0254746e8c980e798f88d8d1bad1b83938af7f579afab6b55220a8baffac84ab" },
      { "nameInfo":"org/mockito/internal/creation/bytebuddy/codegen/MessageClass$MockitoMock$2htoda0op99200N$auxiliary$7m9oaq0S", "hash":"966ae13e45437d2a997c988769b2649fd60fdbd4a4cd197f138074f0bad2b059" },
      { "nameInfo":"org/mockito/internal/creation/bytebuddy/codegen/MessageClass$MockitoMock$2htoda0op99200N", "hash":"067d700caa3692d96f35a77077c337beb2c06308bf45e8a30a40ba83c58592b0" },
      { "nameInfo":"org/mockito/internal/creation/bytebuddy/codegen/MessageClass$MockitoMock$2htoda0op99200N$auxiliary$ql60om3S", "hash":"14e2a45f00f3e143789f7294f0fbf4abaa884585ba54ac4d9f18f127063d9fbd" },
      { "nameInfo":"net/bytebuddy/utility/Invoker$Dispatcher", "hash":"b4371c0b5187b914976c7db687153600bcd974e028cbe432ed804c9b9f84776a" }
    ]
  }
]

See branch here: https://github.com/phipag/mockito-graalvm-example/blob/graal-fix/5.19.1-SNAPSHOT/src/main/resources/META-INF/native-image/com.example/graalvm-example/predefined-classes-config.json

Native tests pass now with Mockito.

com.example.MainTest > testGetMessage() SUCCESSFUL


Test run finished after 83 ms
[         2 containers found      ]
[         0 containers skipped    ]
[         2 containers started    ]
[         0 containers aborted    ]
[         2 containers successful ]
[         0 containers failed     ]
[         1 tests found           ]
[         0 tests skipped         ]
[         1 tests started         ]
[         0 tests aborted         ]
[         1 tests successful      ]
[         0 tests failed          ]

@raphw
Copy link
Member Author

raphw commented Aug 18, 2025

Super. @TimvdLippe - do you have an idea for a test that could start up a Graal VM with the trainingsdata agent enabled? This java process would then produce a JSON file at the specified location on process shut down. We would then simply need to validate that JSON file.

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

Hey @raphw and @TimvdLippe,

To give some inspiration how I do it in my project.

I use the graalvm/setup-graalvm GitHub action to obtain a GraalVM JDK instance and then run the native maven profiles in our project. In your case, this would probably be the gradle equivalent.

After this, I would suggest searching in the in the predefined-classes-config.json for something like org/mockito/internal/creation/bytebuddy/codegen/* and assert that the output is non-empty to pass the GitHub workflow.

https://github.com/aws-powertools/powertools-lambda-java/blob/07dac3a40ac9daa5735a6b2a662b61e1d3e13f60/.github/workflows/check-build.yml#L87

Let me know if you need some help. I am looking very much forward to a SNAPSHOT release of this so that I can unblock some of the pull requests in my project.

@TimvdLippe
Copy link
Contributor

@phipag ah thanks for that! I hadn't had the time to investigate this. Do you mind opening a PR with a setup and a test suite for Graal? You can use the testing subprojects folder for that in mockito-integration-tests/. Thanks!

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

@TimvdLippe – Sure, I can do that. Let me get back to you in a bit once the PR draft is ready.

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

@TimvdLippe, I created a simple test suite for GraalVM here: #3714.

When you execute it using a GraalVM JDK distribution it will generate the metadata files. I verified that without this PR, the reflect-config.json is missing the DummyObject mock and correctly contains it when using this PR.

I am trying to test the CI workflows now to add a GraalVM test job that asserts the contents of this reflect-config.json file.

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

I added a GraalVM job in the ci.yml that asserts this GraalVM metadata logic. The PR is ready for review now. Let me know what you think. The CI should pass after merging this PR and rebasing.

@raphw
Copy link
Member Author

raphw commented Aug 21, 2025

Merged your PR and the test fails @phipag - do you understand why that is?

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

Hmh. Let me check this.

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

The issue is that this line disabled the tracing agent leaving empty metadata files:

enabled = System.getProperty("java.vendor", "").contains("GraalVM")

I didn't catch this earlier since I was looking at my cached GRM files. Let me try to push a fix.

@raphw
Copy link
Member Author

raphw commented Aug 21, 2025

Looks good, should we merge @TimvdLippe?

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

Seems good now. It works in this PR and fails as expected in the other: https://github.com/mockito/mockito/actions/runs/17131718603/job/48597566779

Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, but have some minor comments.

@phipag
Copy link
Contributor

phipag commented Aug 21, 2025

Thanks for your feedback @TimvdLippe. I'll address it tomorrow morning.

@phipag
Copy link
Contributor

phipag commented Aug 22, 2025

Thanks both @raphw and @TimvdLippe. I pushed a commit to address the two comments.

@raphw
Copy link
Member Author

raphw commented Aug 22, 2025

Thanks, I merged them into the branch. Looks good to me.

@TimvdLippe
Copy link
Contributor

Thank you both!

@TimvdLippe TimvdLippe merged commit 37bb3e5 into main Aug 22, 2025
19 checks passed
@TimvdLippe TimvdLippe deleted the avoid-system-loader-graal branch August 22, 2025 17:32
svc-squareup-copybara pushed a commit to cashapp/misk that referenced this pull request Sep 21, 2025
| Package | Type | Package file | Manager | Update | Change |
|---|---|---|---|---|---|
| [org.mockito:mockito-core](https://github.com/mockito/mockito) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`5.19.0` -> `5.20.0` |
|
[io.modelcontextprotocol:kotlin-sdk-server](https://github.com/modelcontextprotocol/kotlin-sdk)
| dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`0.7.1` -> `0.7.2` |
|
[io.modelcontextprotocol:kotlin-sdk-core](https://github.com/modelcontextprotocol/kotlin-sdk)
| dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`0.7.1` -> `0.7.2` |
|
[io.modelcontextprotocol:kotlin-sdk-client](https://github.com/modelcontextprotocol/kotlin-sdk)
| dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`0.7.0` -> `0.7.2` |
|
[com.google.errorprone:error_prone_annotations](https://errorprone.info)
([source](https://github.com/google/error-prone)) | dependencies |
misk/gradle/libs.versions.toml | gradle | minor | `2.41.0` -> `2.42.0` |
| [software.amazon.awssdk:sdk-core](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
| [software.amazon.awssdk:sqs](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
| [software.amazon.awssdk:s3](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
| [software.amazon.awssdk:regions](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
|
[software.amazon.awssdk:dynamodb-enhanced](https://aws.amazon.com/sdkforjava)
| dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
| [software.amazon.awssdk:dynamodb](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
| [software.amazon.awssdk:aws-core](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
| [software.amazon.awssdk:bom](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |
| [software.amazon.awssdk:auth](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | minor |
`2.33.13` -> `2.34.0` |

---

### Release Notes

<details>
<summary>mockito/mockito (org.mockito:mockito-core)</summary>

### [`v5.20.0`](https://github.com/mockito/mockito/releases/tag/v5.20.0)

<sup><sup>*Changelog generated by [Shipkit Changelog Gradle
Plugin](https://github.com/shipkit/shipkit-changelog)*</sup></sup>

##### 5.20.0

- 2025-09-20 - [11
commit(s)](mockito/mockito@v5.19.0...v5.20.0)
by Adrian-Kim, Giulio Longfils, Rafael Winterhalter, dependabot\[bot]
- Bump org.assertj:assertj-core from 3.27.4 to 3.27.5
[(#&#8203;3730)](mockito/mockito#3730)
- Introducing the Ability to Mock Construction of Generic Types
([#&#8203;2401](mockito/mockito#2401))
[(#&#8203;3729)](mockito/mockito#3729)
- Bump com.gradle.develocity from 4.1.1 to 4.2
[(#&#8203;3726)](mockito/mockito#3726)
- Bump graalvm/setup-graalvm from 1.3.6 to 1.3.7
[(#&#8203;3725)](mockito/mockito#3725)
- Bump org.eclipse.platform:org.eclipse.osgi from 3.23.100 to 3.23.200
[(#&#8203;3720)](mockito/mockito#3720)
- Bump graalvm/setup-graalvm from 1.3.5 to 1.3.6
[(#&#8203;3719)](mockito/mockito#3719)
- Bump actions/setup-java from 4 to 5
[(#&#8203;3715)](mockito/mockito#3715)
- Bump com.gradle.develocity from 4.1 to 4.1.1
[(#&#8203;3713)](mockito/mockito#3713)
- Bump bytebuddy from 1.17.6 to 1.17.7
[(#&#8203;3712)](mockito/mockito#3712)
- test: Use Assume.assumeThat for SequencedCollection tests
[(#&#8203;3711)](mockito/mockito#3711)
- Fix [#&#8203;3709](mockito/mockito#3709)
[(#&#8203;3710)](mockito/mockito#3710)
- feat: Add support for JDK21 Sequenced Collections.
[(#&#8203;3708)](mockito/mockito#3708)
- Introducing the Ability to Mock Construction of Generic Types
[(#&#8203;2401)](mockito/mockito#2401)

</details>

<details>
<summary>modelcontextprotocol/kotlin-sdk
(io.modelcontextprotocol:kotlin-sdk-server)</summary>

###
[`v0.7.2`](https://github.com/modelcontextprotocol/kotlin-sdk/releases/tag/0.7.2)

[Compare
Source](modelcontextprotocol/kotlin-sdk@0.7.1...0.7.2)

##### What's Changed

- migration from `jreleaser` to `mavenPublish` plugin by
[@&#8203;devcrocod](https://github.com/devcrocod) in
[#&#8203;277](modelcontextprotocol/kotlin-sdk#277)
- Generate test report by [@&#8203;kpavlov](https://github.com/kpavlov)
in
[#&#8203;271](modelcontextprotocol/kotlin-sdk#271)
- Move `generateLibVersion` task to `kotlin-sdk-core` by
[@&#8203;devcrocod](https://github.com/devcrocod) in
[#&#8203;274](modelcontextprotocol/kotlin-sdk#274)
-
[#&#8203;196](modelcontextprotocol/kotlin-sdk#196)
Update build configuration and workflows for enhanced local publ… by
[@&#8203;kpavlov](https://github.com/kpavlov) in
[#&#8203;275](modelcontextprotocol/kotlin-sdk#275)
- Add Stdio coverage for integration tests by
[@&#8203;skarpovdev](https://github.com/skarpovdev) in
[#&#8203;276](modelcontextprotocol/kotlin-sdk#276)
- Bump io.kotest:kotest-assertions-json from 5.9.1 to 6.0.3 by
[@&#8203;dependabot](https://github.com/dependabot)\[bot] in
[#&#8203;247](modelcontextprotocol/kotlin-sdk#247)
- migration from `jreleaser` to `mavenPublish` plugin by
[@&#8203;devcrocod](https://github.com/devcrocod) in
[#&#8203;277](modelcontextprotocol/kotlin-sdk#277)

**Full Changelog**:
<modelcontextprotocol/kotlin-sdk@0.7.1...0.7.2>

</details>

<details>
<summary>google/error-prone
(com.google.errorprone:error_prone_annotations)</summary>

###
[`v2.42.0`](https://github.com/google/error-prone/releases/tag/v2.42.0):
Error Prone 2.42.0

New checks:

-
[`ExplicitArrayForVarargs`](https://errorprone.info/bugpattern/ExplicitArrayForVarargs):
discourage unnecessary explicit construction of an array to provide
varargs.
-
[`FloggerPerWithoutRateLimit`](https://errorprone.info/bugpattern/FloggerPerWithoutRateLimit):
discourage Flogger's `perUnique` without rate limiting
- [`StringJoin`](https://errorprone.info/bugpattern/StringJoin): Ban
`String.join(CharSequence)` and `String.join(CharSequence,
CharSequence)`
-
[`ThreadBuilderNameWithPlaceholder`](https://errorprone.info/bugpattern/ThreadBuilderNameWithPlaceholder):
Do not allow placeholders in `Thread.Builder.name(String)` or
`name(String, int)`.

Changes:

- The return type of `ASTHelpers.asFlagSet` has changed. The previous
type was `EnumSet<Flags.Flag>`, where `Flags.Flag` is an enum in the
javac class `Flags`. A recent JDK change has replaced that enum with a
new top-level enum called `FlagsEnum`. It is not possible to change
`ASTHelpers.asFlagSet` in a way that would be type-safe and compatible
with the enums from JDKs both before and after the change. Instead, the
method now returns `ImmutableSet<String>`, where the strings come from
the `toString()` of the enum constants. That means they are `"native"`,
`"abstract"`, etc.
- Flag `IO.print[ln]()` in
[`SystemOut`](https://errorprone.info/bugpattern/SystemOut).

Full changelog:
<google/error-prone@v2.41.0...v2.42.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am
every weekday" in timezone Australia/Melbourne, Automerge - At any time
(no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Never, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://github.com/renovatebot/renovate).

GitOrigin-RevId: 8ecb809cff408a555b4ee0773a9fb8cdca50b95c
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.

4 participants