Skip to content

fix(jsii-pacmak): toString() on anonymous classes does not call JavaScript implementation#5027

Merged
mergify[bot] merged 9 commits intomainfrom
huijbers/tostring-through-interface
Jan 23, 2026
Merged

fix(jsii-pacmak): toString() on anonymous classes does not call JavaScript implementation#5027
mergify[bot] merged 9 commits intomainfrom
huijbers/tostring-through-interface

Conversation

@rix0rrr
Copy link
Copy Markdown
Contributor

@rix0rrr rix0rrr commented Jan 23, 2026

In recent changes, we dropped as many methods from Jsii$Proxy as possible. This includes the implementation of toString() from Jsii$Proxy, which means that toString() falls back to the Java implementation instead of the JavaScript one.

@Jsii(module = $Module.class, fqn = "aws-cdk-lib.IResolvable")
@Proxy(IResolvable.Jsii$Proxy.class)
public interface IResolvable extends JsiiSerializable {
  List<String> getCreationStack();
  ResolutionTypeHint getTypeHint();
  Object resolve(@NotNull IResolveContext paramIResolveContext);
  
  String toString();   // <---- ⚠️ note this!
  
  public static interface Jsii$Default extends IResolvable {
    @NotNull
    default List<String> getCreationStack() {
       // ... 
    }
    
    @Nullable
    default ResolutionTypeHint getTypeHint() {
       // ... 
    }
    
    @NotNull
    default Object resolve(@NotNull IResolveContext context) {
       // ... 
    }

    // <--- ❌ but missing here!
  }
}

This doesn't fail because only there is there also a default toString() implementation on all objects in Java.

There was no problem when we called toString() on a proxy of a public JSII class, but in case we were using a pure interface proxy (when the concrete class was private or even anonymous), we wouldn't forward to the JavaScript-side toString() but call the default Java implementation instead.

Fix that and add a test for this behavior.


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

…mplementation

In recent changes, it looks like we dropped the implementation of
`toString()` from a `Jsii$Default` interface (and didn't pick it up
anywhere else), which means that `toString()` falls back to the Java
implementation instead of the JavaScript one.

This is only a problem in Java because only there is there also a
default `toString()` implementation on all objects.

Fix that and add a test for this behavior.
@rix0rrr rix0rrr requested a review from a team January 23, 2026 12:48
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 23, 2026
@rix0rrr rix0rrr changed the title fix(jsii-pacmak): toString via interface no longer calls JavaScript implementation fix(jsii-pacmak): toString() on anonymous classes does not call JavaScript implementation Jan 23, 2026
@rix0rrr rix0rrr marked this pull request as ready for review January 23, 2026 15:46
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jan 23, 2026

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Jan 23, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jan 23, 2026

Merging (with squash)...

@mergify mergify bot added the queued label Jan 23, 2026
@mergify mergify bot merged commit d6a243b into main Jan 23, 2026
38 checks passed
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jan 23, 2026

Merge Queue Status

✅ The pull request has been merged at 5093c3e

This pull request spent 9 seconds in the queue, with no time running CI.
The checks were run in-place.

Required conditions to merge

@mergify mergify bot deleted the huijbers/tostring-through-interface branch January 23, 2026 21:04
@mergify mergify bot removed pr/ready-to-merge This PR is ready to be merged. queued labels Jan 23, 2026
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Feb 3, 2026
…java (#36843)

### Issue # (if applicable)

Closes #36832

### Reason for this change

To fix the bug mentioned in the issue...



### Description of changes

Bump the version `jsii-pacmak` to pull in the [jsii fix](aws/jsii#5027).



### Describe any new or updated permissions being added

None




### Description of how you validated changes

No code changes.



### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
ozelalisen pushed a commit to aws/aws-cdk that referenced this pull request Feb 3, 2026
…java (#36843)

### Issue # (if applicable)

Closes #36832

### Reason for this change

To fix the bug mentioned in the issue...



### Description of changes

Bump the version `jsii-pacmak` to pull in the [jsii fix](aws/jsii#5027).



### Describe any new or updated permissions being added

None




### Description of how you validated changes

No code changes.



### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants