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

Avoid NullPointerException in OpenRewriteMethod #739

Closed
xiaowu2012 opened this issue Feb 27, 2023 · 2 comments · Fixed by #750
Closed

Avoid NullPointerException in OpenRewriteMethod #739

xiaowu2012 opened this issue Feb 27, 2023 · 2 comments · Fixed by #750
Labels
type: enhancement New feature or request
Milestone

Comments

@xiaowu2012
Copy link

xiaowu2012 commented Feb 27, 2023

Caused by: java.lang.NullPointerException: Cannot invoke "org.openrewrite.java.tree.JavaType$FullyQualified.getFullyQualifiedName()" because the return value of "org.openrewrite.java.tree.TypeUtils.asFullyQualified(org.openrewrite.java.tree.JavaType)" is null

Current Version:

 @Override
    public Optional<String> getReturnValue() {
        TypeTree returnTypeExpression = getMethodDecl().getReturnTypeExpression();
        if (returnTypeExpression == null || returnTypeExpression.getType() == JavaType.Primitive.Void) {
            return Optional.empty();
        }

        return Optional.of(TypeUtils.asFullyQualified(returnTypeExpression.getType()).getFullyQualifiedName());
    }

Fixed version:

  @Override
    public Optional<String> getReturnValue() {
        TypeTree returnTypeExpression = getMethodDecl().getReturnTypeExpression();
        if (returnTypeExpression == null || returnTypeExpression.getType() == JavaType.Primitive.Void) {
            return Optional.empty();
        }

        JavaType.FullyQualified jfq = TypeUtils.asFullyQualified(returnTypeExpression.getType());
        if(jfq == null ) {
            return Optional.empty();
        } else {
            return Optional.of(jfq.getFullyQualifiedName());
        }
    }
@xiaowu2012 xiaowu2012 added 3.0.0 Spring Boot 3.0.0 good first issue Good for newcomers type: enhancement New feature or request upgrade:boot-recipe labels Feb 27, 2023
@fabapp2 fabapp2 changed the title 3.0 Upgrade Recipe: NullPointerException in OpenRewriteMethod Avoid NullPointerException in OpenRewriteMethod Feb 28, 2023
@fabapp2 fabapp2 removed good first issue Good for newcomers upgrade:boot-recipe 3.0.0 Spring Boot 3.0.0 labels Feb 28, 2023
@fabapp2 fabapp2 added this to the v0.15.0 milestone Feb 28, 2023
@fabapp2
Copy link
Collaborator

fabapp2 commented Feb 28, 2023

Hi @xiaowu2012
Thanks for the proposed improvement. 🚀
Could you maybe contribute with a test?

@sanagaraj-pivotal
Copy link
Contributor

This is fixed now: #750

@fabapp2 fabapp2 linked a pull request Jun 13, 2023 that will close this issue
@fabapp2 fabapp2 closed this as completed Jun 13, 2023
@fabapp2 fabapp2 modified the milestones: v0.15.0, v0.14.0 Jun 13, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants