Skip to content

Fix smithyFormat classpath serialization error#161

Merged
yasmewad merged 1 commit intomainfrom
fix-classpath
Feb 19, 2026
Merged

Fix smithyFormat classpath serialization error#161
yasmewad merged 1 commit intomainfrom
fix-classpath

Conversation

@yasmewad
Copy link
Contributor

Background

Root Cause

SmithyUtils.RunCli executes the Smithy CLI inside a custom URLClassLoader isolated from Gradle's daemon classloader. When the CLI throws ModelSyntaxException, the original catch block preserved the full cause chain via throw new RuntimeException(e). Gradle's daemon serializer (ExceptionPlaceholder) then tries to introspect the exception's fields -- but ModelSyntaxException and ShapeId were loaded by the isolated classloader, not the daemon's. Java class identity is per classloader instance, so the lookup fails even though smithy-model is already a plugin dependency.

Fix

In SmithyUtils.RunCli.execute(), unwrap the cause chain to the root, extract only the message string (falling back to the class name if the message is null), and throw a plain GradleException with no cause attached, so the daemon serializer never encounters the isolated types. Users still see the real error (e.g. "Cannot format invalid models: Syntax error at line 105, column 8").

An alternative is to add smithy-model to the daemon classpath. smithy-model is already a plugin dependency, so it is present in the daemon's classpath. This still does not work as the ModelSyntaxException instance was created by the isolated URLClassLoader, and Java's class identity check requires the same classloader instance, not just the same JAR. Fixing this would require removing the classloader isolation entirely, which reintroduces ZipException: invalid LOC header errors from stale cached JARs that required us to isolate the Smithy CLI classloader in the first place.

Testing

  • How did you test these changes?

Added a regression test.

Links

  • Links to additional context, if necessary
  • Issue #, if applicable (see here for a list of keywords to use for linking issues)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

When smithyFormat fails on invalid syntax, the ModelSyntaxException
thrown inside the isolated URLClassLoader cannot be serialized by
Gradle's daemon (ShapeId is not visible to the daemon classloader).
Strip the cause chain at the worker boundary and rethrow as a plain
GradleException with only the root cause message.
@yasmewad yasmewad requested a review from a team as a code owner February 19, 2026 03:09
@yasmewad yasmewad requested a review from joewyz February 19, 2026 03:09
.buildAndFail();

// The real error from the Smithy formatter must be present.
Assertions.assertTrue(
Copy link
Contributor

Choose a reason for hiding this comment

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

Using assertThat with containsString from hamcrest will give better errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, can do it as follow up.

@yasmewad yasmewad merged commit a770f94 into main Feb 19, 2026
4 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