Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java: unable to override protected methods #903

Closed
1 of 4 tasks
eladb opened this issue Oct 23, 2019 · 0 comments · Fixed by #905
Closed
1 of 4 tasks

java: unable to override protected methods #903

eladb opened this issue Oct 23, 2019 · 0 comments · Fixed by #905
Assignees
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p0

Comments

@eladb
Copy link
Contributor

eladb commented Oct 23, 2019

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)

General Information

  • JSII Version: 0.19.0
  • Platform: any

What is the problem?

When trying to override a protected jsii method in Java, the following error is printed:

software.amazon.jsii.JsiiException: Resolution error: Unable to find callback method with signature: protected java.lang.String com.amazon.noopf.tenantresourcegenrator.NoOpfStack.allocateLogicalId(software.amazon.awscdk.core.CfnElement).

An example would be to try and override the allocateLogicalId method in a subclass of @aws-cdk/core.Stack:

public class MyStack extends Stack {
    private final String STACK_MAJOR_VERSION = "v1";

    public MyStack(App parent, String name, MyStackProps props) {
        super(parent, name, props);
        //CfnResource cfnResource = new CfnResource(...);
        //...
    }

    @Override
    protected String allocateLogicalId(CfnElement cfnElement) {
        return super.allocateLogicalId(cfnElement) + STACK_MAJOR_VERSION;
    }
}

Workaround

A workaround (credits @RomainMuller) is to change the override from protected to public.

@eladb eladb added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 23, 2019
@RomainMuller RomainMuller self-assigned this Oct 23, 2019
@RomainMuller RomainMuller added p0 effort/small Small work item – less than a day of effort labels Oct 23, 2019
RomainMuller added a commit that referenced this issue Oct 23, 2019
The code looking for overrides implementations was using the
`Class#getMethods` method, but this only considers `public` members of
the class. Chanegd to `#getDeclaredMethods` which accounts for *all* the
methods.

Fixes #903
RomainMuller added a commit that referenced this issue Oct 24, 2019
)

The code looking for overrides implementations was using the
`Class#getMethods` method, but this only considers `public` members of
the class. Chanegd to `#getDeclaredMethods` which accounts for *all* the
methods.

Fixes #903
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants