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

Update made by URLConstructorsToURI recipe can yield IllegalArgumentException #620

Open
cjobinabo opened this issue Dec 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@cjobinabo
Copy link
Contributor

cjobinabo commented Dec 5, 2024

What version of OpenRewrite are you using?

I am using

  • rewrite-rewrite-migrate-java 2.30.1

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

What is the smallest, simplest way to reproduce the problem?

The following conversion by the URLConstructorsToURI recipe yields an IllegalArgumentException:
Before:
url = new URL("META-INF/wsdl/GarageSaleCCManagerService.wsdl");
After:
url = URI.create("META-INF/wsdl/GarageSaleStoreManagerService.wsdl").toURL()

Here is the full Stack Trace:

[INFO] [err] Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.IllegalArgumentException: URI is not absolute [in thread "Default Executor-thread-8"]
[INFO] [err]    at java.base/java.net.URL.of(URL.java:862)
[INFO] [err]    at java.base/java.net.URI.toURL(URI.java:1172)
[INFO] [err]    at com.ibm.websphere.svt.gs.gsdb.jaxws.client.GarageSaleStoreManagerService.<clinit>(GarageSaleStoreManagerService.java:31)

It appears that the URI.create method expects an absolute URI. The proposal here is to attempt to validate that the String literal passed to the method is absolute before performing the conversion.

It's possible the following recipe might help here
RemoveStringFlag.java

            private boolean isFeatureKey(Expression firstArgument) {
                return CursorUtil.findCursorForTree(getCursor(), firstArgument)
                               .bind(c -> ConstantFold.findConstantLiteralValue(c, String.class))
                               .map(featureKey::equals)
                               .orSome(false);
@cjobinabo cjobinabo added the bug Something isn't working label Dec 5, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

1 participant