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

[Bug]: Linkage error when loading interface implementation of a compiler plugin from a Ballerina Tool #41957

Closed
Xenowa opened this issue Jan 9, 2024 · 3 comments · Fixed by #42055
Assignees
Labels
Area/CLI Ballerina CLI related issues. Reason/Complex Issue occurred due to complex scenario. Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug
Milestone

Comments

@Xenowa
Copy link

Xenowa commented Jan 9, 2024

Description

When a Ballerina compiler plugin implements an interface from a Ballerina tool, an attempt to load this interface implementation through the Ballerina tool using URLClassLoader with the parent class loader set as CustomToolClassLoader, and employing ServiceLoader, it results in a java.lang.LinkageError. The error specifically points to an attempted duplicate interface definition, preventing the expected loading and invocation of methods within the implemented class of the compiler plugin.

Steps to Reproduce

Clone the thin-jar-service-loading branch of the repository here and follow the instructions in the README file.

Affected Version(s)

Ballerina 2201.8.2

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

Area/CLI, Team/DevTools

Suggested assignee(s) (optional)

No response

@Xenowa Xenowa added the Type/Bug label Jan 9, 2024
@ballerina-bot ballerina-bot added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Jan 9, 2024
@MaryamZi MaryamZi added Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) and removed Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime labels Jan 9, 2024
@gayaldassanayake gayaldassanayake added the Area/CLI Ballerina CLI related issues. label Jan 9, 2024
@gayaldassanayake gayaldassanayake self-assigned this Jan 9, 2024
@gayaldassanayake
Copy link
Contributor

The issue occurs when there is an SPI (Service Loading) within the tool.

The tools are running on a separate self-first class loader named CustomToolClassLoader implemented in ballerina-lang. This overrides the default URLClassLoader behaviour (parent-first) to load the classes from the urls first and then from the parent.

However there is a bug in this logic where it loads the class without checking if it has been loaded first. Looking if the class is already loaded before class loading within CustomToolClassLoader->loadClass fixes the issue.

In the mean time, we need to figure out if we can implement a custom class loader within the scan tool and properly load classes without any linkage errors as a workaround. Will update the thread with the progress.

@gayaldassanayake
Copy link
Contributor

Provided a pack with the fix. Since there might be other changes that are needed, will not make a PR until the required changes are finalized.

Copy link

github-actions bot commented Feb 1, 2024

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@gayaldassanayake gayaldassanayake added the Reason/Complex Issue occurred due to complex scenario. label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/CLI Ballerina CLI related issues. Reason/Complex Issue occurred due to complex scenario. Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants