Skip to content

URLThreeArgumentConstructor does not introduce newly thrown exceptionΒ #467

@timtebeek

Description

@timtebeek

What version of OpenRewrite are you using?

  • OpenRewrite v8.24.0
  • rewrite-migrate-java v2.12.0

How are you running OpenRewrite?

I'm running org.openrewrite.java.migrate.net.URLConstructorsToURI.URLThreeArgumentConstructorRecipe, via:

description = "Converts `new URL(String, String, String)` constructors to `new URI(...).toURL()`."
)
public static class URLThreeArgumentConstructor {
@BeforeTemplate
URL urlConstructor(String protocol, String host, String file) throws Exception {
return new URL(protocol, host, file);
}
@AfterTemplate
URL newUriToUrl(String protocol, String host, String file) throws Exception {
return new URI(protocol, null, host, -1, file, null, null).toURL();
}
}
@RecipeDescriptor(

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

class A {
    URL urlConstructor(String protocol, String host, String file) throws IOException {
        return new URL(protocol, host, file);
    }
}

What did you expect to see?

class A {
    URL urlConstructor(String protocol, String host, String file) throws URISyntaxException, IOException {
            return new URI(protocol, null, host, -1, file, null, null).toURL();
        }
}

What did you see instead?

class A {
    URL urlConstructor(String protocol, String host, String file) throws IOException {
            return new URI(protocol, null, host, -1, file, null, null).toURL();
        }
}

Note the lacking throws URISyntaxException.

What is the full stack trace of any errors you encountered?

Compiler error, as URISyntaxException does not extend IOException, in contrast to MalformedURLException thrown before. As reported by @IanDarwin

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions