Skip to content

Cannot invoke "org.openrewrite.java.tree.JavaType$FullyQualified.getFullyQualifiedName()" #601

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

Open
marcgemis opened this issue Dec 20, 2022 · 7 comments
Assignees
Labels
type: bug Something isn't working

Comments

@marcgemis
Copy link

Describe the bug
Cannot generate a sbu30-report because the program reports a
Applying recipe 'sbu30-report'
Action [SpringBootUpgradeReportAction] 'Creates a Upgrade report for Spring Boot 3.' failed: 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
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.

To Reproduce

  • Downloaded spring-boot-migrator
  • started it with java -Dsbm.gitSupportEnabled=false --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED -jar spring-boot-migrator.jar
    as our company uses Perforce and not Git.
  • scanned my project, a Spring Cloud Gateway project on Spring Boot 2.7.5
    [ok] Found pom.xml.
    [ok] 'sbm.gitSupportEnabled' is 'false', Nothing will be committed.
    [ok] Required Java version (17) was found.
    [ok] Found required source dir 'src/main/java'.

-then I tried to generate a report

api-gateway:> apply sbu30-report
Applying recipe 'sbu30-report'
Action [SpringBootUpgradeReportAction] 'Creates a Upgrade report for Spring Boot 3.' failed: 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
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.

Expected behavior
The Spring Boot migration report should be generated

Stacktrace
If applicable, add the (sanitized) stacktrace here.

api-gateway:> stacktrace
org.springframework.sbm.engine.recipe.ActionFailedException: Action [SpringBootUpgradeReportAction] 'Creates a Upgrade report for Spring Boot 3.' failed: 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
at org.springframework.sbm.engine.recipe.Action.applyWithStatusEvent(Action.java:43)
at org.springframework.sbm.engine.recipe.Recipe.apply(Recipe.java:101)
at org.springframework.sbm.engine.commands.ApplyCommand.execute(ApplyCommand.java:61)
at org.springframework.sbm.shell.ApplyShellCommand.apply(ApplyShellCommand.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.shell.command.invocation.InvocableShellMethod.doInvoke(InvocableShellMethod.java:306)
at org.springframework.shell.command.invocation.InvocableShellMethod.invoke(InvocableShellMethod.java:232)
at org.springframework.shell.command.CommandExecution$DefaultCommandExecution.evaluate(CommandExecution.java:158)
at org.springframework.shell.Shell.evaluate(Shell.java:208)
at org.springframework.shell.Shell.run(Shell.java:140)
at org.springframework.shell.jline.InteractiveShellRunner.run(InteractiveShellRunner.java:73)
at org.springframework.shell.DefaultShellApplicationRunner.run(DefaultShellApplicationRunner.java:65)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at org.springframework.sbm.SpringShellApplication.main(SpringShellApplication.java:27)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
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
at org.springframework.sbm.java.impl.OpenRewriteMethod.getReturnValue(OpenRewriteMethod.java:167)
at org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder.lambda$apply$1(SpringBeanMethodDeclarationFinder.java:52)
at java.base/java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:632)
at org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder.lambda$apply$2(SpringBeanMethodDeclarationFinder.java:52)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder.lambda$apply$6(SpringBeanMethodDeclarationFinder.java:56)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder.apply(SpringBeanMethodDeclarationFinder.java:45)
at org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder.apply(SpringBeanMethodDeclarationFinder.java:30)
at org.springframework.sbm.engine.context.ProjectContext.search(ProjectContext.java:77)
at org.springframework.sbm.boot.upgrade_27_30.report.helper.CommonsMultipartResolverHelper.evaluate(CommonsMultipartResolverHelper.java:51)
at org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection.shouldRender(SpringBootUpgradeReportSection.java:77)
at org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportAction.lambda$apply$0(SpringBootUpgradeReportAction.java:124)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportAction.apply(SpringBootUpgradeReportAction.java:125)
at org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportAction.applyInternal(SpringBootUpgradeReportAction.java:214)
at org.springframework.sbm.engine.recipe.Action.applyWithStatusEvent(Action.java:37)
... 28 more

Desktop (please complete the following information):

  • OS: Mac OS 12.5.1, Java 17
  • Spring Boot Migrator 0.13.0
  • java -version
    openjdk version "17.0.3" 2022-04-19
    OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7)
    OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode)

Additional context

There was no problem to generate the report boot-2.7-3.0-upgrade-report

@marcgemis
Copy link
Author

This problem did not occur in other projects, only on a project with api-gateway.
Since I use Keycloak in one of my microservices, I cannot upgrade to Spring Boot 3.0 at the moment, so it is not urgent

@fabapp2
Copy link
Contributor

fabapp2 commented Jan 3, 2023

Hi @marcgemis
Thanks for reporting and a Happy New Year 🚀

Could you try using spring-boot-upgrade.jar to see if the error persists? Looking at the stacktrace I am afraid it doesn't but since we moved the Boot Upgrade functionality to it's own application it could be that the functionality just didn't get enough love since then. 🤞

@fabapp2 fabapp2 added the type: bug Something isn't working label Jan 3, 2023
@fabapp2 fabapp2 self-assigned this Jan 3, 2023
@marcgemis
Copy link
Author

Hello @fabapp2 ,

best wishes to you as well,.
I downloaded the spring-boot-upgrade.jar and tried it on the same api-gateway project.
I get the same problem.

I ran it with
java -Dsbm.gitSupportEnabled=false -Dserver.port=8432 --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED -jar spring-boot-upgrade.jar <path_to_my_project>

after a bit of experimenting, as I could not find any documentation on running spring-boot-upgrade.jar

@marcgemis
Copy link
Author

I've tried spring-boot-upgrade on some other projects we have and it fails on them as well.
So far it works for a simple Eureka-server project and one microservice we have.
We try to set up all our microservices in the same way. So it's hard to tell why it works for one of them and not for the others.

I just noticed the exception is slightly different for spring-boot-upgrade.jar

Scanning /Users/mgemis/Projects/p4/awp/bluecloud/microservices/jdf-service
07:52:28.055 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:765)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
at org.springframework.sbm.SpringBootUpgradeReportApp.main(SpringBootUpgradeReportApp.java:31)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: org.springframework.sbm.engine.recipe.ActionFailedException: Action [SpringBootUpgradeReportAction] 'Creates a Upgrade report for Spring Boot 3.' failed: 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
at org.springframework.sbm.engine.recipe.Action.applyWithStatusEvent(Action.java:43)
at org.springframework.sbm.engine.recipe.Recipe.apply(Recipe.java:101)
at org.springframework.sbm.engine.commands.ApplyCommand.execute(ApplyCommand.java:61)
at org.springframework.sbm.SpringBootMigratorRunner.run(SpringBootMigratorRunner.java:46)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762)
... 13 common frames omitted
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
at org.springframework.sbm.java.impl.OpenRewriteMethod.getReturnValue(OpenRewriteMethod.java:167)
at org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder.lambda$apply$1(SpringBeanMethodDeclarationFinder.java:52)

but that is to be expected I assume

@marcgemis
Copy link
Author

I started with a fresh project, and found that when I add this stripped down version of my SecurityConfig to the project, the error occurs

package com.example.demo;

import java.util.Collection;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper;
import org.springframework.security.oauth2.client.oidc.web.server.logout.OidcClientInitiatedServerLogoutSuccessHandler;
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.header.XFrameOptionsServerHttpHeadersWriter.Mode;

import lombok.RequiredArgsConstructor;

@configuration
@requiredargsconstructor
public class SecurityConfig {

private final ApplicationContext context;


private <T> T getBeanOrNull(Class<T> beanClass) {
return getBeanOrNull(ResolvableType.forClass(beanClass));
}

@SuppressWarnings("unchecked")
private <T> T getBeanOrNull(ResolvableType type) {
if (this.context == null) {
    return null;
}
String[] names = this.context.getBeanNamesForType(type);
if (names.length == 1) {
    return (T) this.context.getBean(names[0]);
}
return null;
}

}

I don't know why the method was added. We do not need it anymore. However, the exact same code is not in any of the other projects that fail.

@fabapp2
Copy link
Contributor

fabapp2 commented Jan 4, 2023

Thanks a lot for isolating the issue, that's very helpful.
I hope it will give me an idea of why it goes kaboom.
Also planning to upgrade to the latest OpenRewrite before.
I will then look into your issue (🤞) today and update the console output of spring-boot-upgrade.jar as well as the README thanks for pointing this out.

@marcgemis
Copy link
Author

marcgemis commented Jan 4, 2023

Please note that I also reported on issue against OpenRewrite : openrewrite/rewrite#2547
I had some problems with the Jakarta rewrite scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants