Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

IllegalArgumentException: Code should not be empty #1365

Closed
AndersClausen opened this issue Dec 10, 2021 · 14 comments
Closed

IllegalArgumentException: Code should not be empty #1365

AndersClausen opened this issue Dec 10, 2021 · 14 comments

Comments

@AndersClausen
Copy link

Hi

I'm using spring boot 2.6.2-SNAPSHOT, Java 17 and spring native 0.11.1-SNAPSHOT and I'm getting an error when running mvn clean install, which I'm not quite sure how to debug. This is the error I'm seeing:

2021-12-10 11:27:18.490  WARN 15584 --- [           main] .s.c.a.BuildTimeBeanDefinitionsRegistrar : BeanDefinitionRegistryPostProcessor with bean name traceHookRegisteringBeanDefinitionRegistryPostProcessor is going to be invoked again at runtime, set a role infrastructure to avoid this
java.lang.IllegalArgumentException: Code should not be empty
	at org.springframework.aot.context.bootstrap.generator.bean.support.MultiCodeBlock.add(MultiCodeBlock.java:53)
	at org.springframework.aot.context.bootstrap.generator.bean.support.MultiCodeBlock.add(MultiCodeBlock.java:44)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.lambda$writeAll$10(ParameterWriter.java:174)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeAll(ParameterWriter.java:174)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:127)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:79)
	at org.springframework.aot.context.bootstrap.generator.bean.support.ParameterWriter.writeParameterValue(ParameterWriter.java:68)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.writeArgumentValue(DefaultBeanRegistrationWriter.java:258)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.handleArgumentValues(DefaultBeanRegistrationWriter.java:242)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.handleBeanDefinitionMetadata(DefaultBeanRegistrationWriter.java:222)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.initializeBeanDefinitionRegistrar(DefaultBeanRegistrationWriter.java:177)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.writeBeanRegistration(DefaultBeanRegistrationWriter.java:150)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.beanRegistrationMethod(DefaultBeanRegistrationWriter.java:354)
	at org.springframework.aot.context.bootstrap.generator.bean.DefaultBeanRegistrationWriter.writeBeanRegistration(DefaultBeanRegistrationWriter.java:106)
	at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.writeBeanDefinitions(ApplicationContextAotProcessor.java:127)
	at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.bootstrapMethod(ApplicationContextAotProcessor.java:103)
	at org.springframework.aot.context.bootstrap.generator.ApplicationContextAotProcessor.process(ApplicationContextAotProcessor.java:95)
	at org.springframework.aot.test.context.bootstrap.generator.TestContextAotProcessor.generateTestContext(TestContextAotProcessor.java:112)
	at org.springframework.aot.test.context.bootstrap.generator.TestContextAotProcessor.generateTestContexts(TestContextAotProcessor.java:81)
	at org.springframework.aot.test.build.TestContextBootstrapContributor.contribute(TestContextBootstrapContributor.java:61)
	at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:91)
	at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:71)
	at org.springframework.aot.test.build.GenerateTestBootstrapCommand.call(GenerateTestBootstrapCommand.java:111)
	at org.springframework.aot.test.build.GenerateTestBootstrapCommand.call(GenerateTestBootstrapCommand.java:47)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
	at picocli.CommandLine.access$1300(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
	at picocli.CommandLine.execute(CommandLine.java:2078)
	at org.springframework.aot.test.build.GenerateTestBootstrapCommand.main(GenerateTestBootstrapCommand.java:116)
[ERROR] 
org.apache.maven.plugin.MojoExecutionException: Could not exec java
    at org.springframework.aot.maven.AbstractBootstrapMojo.forkJvm (AbstractBootstrapMojo.java:187)
    at org.springframework.aot.maven.TestGenerateMojo.execute (TestGenerateMojo.java:131)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: org.apache.maven.plugin.MojoExecutionException: Bootstrap code generator finished with exit code: 1
    at org.springframework.aot.maven.AbstractBootstrapMojo.forkJvm (AbstractBootstrapMojo.java:184)
    at org.springframework.aot.maven.TestGenerateMojo.execute (TestGenerateMojo.java:131)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
[ERROR] [org.springframework.aot.maven.AbstractBootstrapMojo.forkJvm(AbstractBootstrapMojo.java:187), org.springframework.aot.maven.TestGenerateMojo.execute(TestGenerateMojo.java:131), org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148), org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117), org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81), org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56), org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128), org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305), org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192), org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105), org.apache.maven.cli.MavenCli.execute(MavenCli.java:957), org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289), org.apache.maven.cli.MavenCli.main(MavenCli.java:193), java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method), java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77), java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43), java.base/java.lang.reflect.Method.invoke(Method.java:568), org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282), org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225), org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406), org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347), org.codehaus.classworlds.Launcher.main(Launcher.java:47)]

Any ideas or suggestions to how I can debug it further or get past this? Many thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 10, 2021
@snicoll
Copy link
Contributor

snicoll commented Dec 13, 2021

One of the possible reasons is that the AOT engine is trying to write a parameter that it does not handle (which reminds me we should improve error handling).

It is impossible for us to say without a small sample that replicate the problem. Can you please share that?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Dec 13, 2021
@mraible
Copy link

mraible commented Dec 13, 2021

I encountered this when trying to upgrade my JHipster examples to use Spring Native 0.11.0. You can reproduce with the following steps:

git clone -b spring-native-0.11 https://github.com/mraible/spring-native-examples.git
cd spring-native-examples/spring-native-mvc
./mvnw package -Pnative -DskipTests

Results in:

[ERROR] Failed to execute goal org.springframework.experimental:spring-aot-maven-plugin:0.11.0:test-generate 
(test-generate) on project jhipster: Build failed during Spring AOT test code generation: Could not exec java: 
Bootstrap code generator finished with exit code: 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Execution time: 12 s.

My Java version:

openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05)
OpenJDK 64-Bit Server VM GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 13, 2021
@snicoll
Copy link
Contributor

snicoll commented Dec 13, 2021

@mraible thanks for the sample. There are more than one reason why such a generic exception could be raised and I'd like @AndersClausen to share his sample and that yours is in a separate issue potentially. From a quick look at your project, you are using mockito and it isn't supported (never was) see #1343. If you're still having that issue after removing the use of Mockito, please create a separate issue.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 13, 2021
mraible pushed a commit to mraible/spring-native-examples that referenced this issue Dec 13, 2021
@mraible
Copy link

mraible commented Dec 13, 2021

@snicoll Thanks for the tip. Removing Mockito as a dependency and any tests that referenced it solved this issue for me.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 13, 2021
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 13, 2021
@mraible
Copy link

mraible commented Dec 14, 2021

@snicoll Do you know why removing Mockito is necessary for Spring MVC but not WebFlux? Everything builds just fine in my WebFlux app and it has Mockito as a dependency:

$ mvn dependency:tree | grep mockito
[INFO] |  +- org.mockito:mockito-core:jar:4.0.0:test
[INFO] |  +- org.mockito:mockito-junit-jupiter:jar:4.0.0:test

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 14, 2021
@snicoll
Copy link
Contributor

snicoll commented Dec 15, 2021

Having mockito on the classpath is not a problem at all. It's using it in a test that will cause a definition to be created. If you're not using mockito, the post processor will be created with an empty set of definitions.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 15, 2021
@mraible
Copy link

mraible commented Dec 15, 2021

@snicoll That's not the behavior I'm seeing. For Spring MVC, I had to exclude Mockito and then delete the tests for ./mvnw package -Pnative,prod -DskipTests to work. For Spring WebFlux, I have to do neither and the same command works. I do have tests that import Mockito with WebFlux. If I exclude Mockito in my pom.xml, the ./mvnw command fails:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project jhipster: Compilation failure: Compilation failure:
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/test/java/com/mycompany/myapp/config/TestSecurityConfiguration.java:[3,26] package org.mockito does not exist
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/test/java/com/mycompany/myapp/config/TestSecurityConfiguration.java:[3,1] static import only from classes and interfaces
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/test/java/com/mycompany/myapp/security/oauth2/AudienceValidatorTest.java:[4,26] package org.mockito does not exist
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/test/java/com/mycompany/myapp/security/oauth2/AudienceValidatorTest.java:[4,1] static import only from classes and interfaces
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/test/java/com/mycompany/myapp/security/oauth2/AudienceValidatorTest.java:[5,26] package org.mockito does not exist
[ERROR] /Users/mraible/dev/spring-native-examples/spring-native-webflux/src/test/java/com/mycompany/myapp/security/oauth2/AudienceValidatorTest.java:[5,1] static import only from classes and interfaces

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 15, 2021
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 15, 2021
@AndersClausen
Copy link
Author

AndersClausen commented Dec 15, 2021

I'm sorry @snicoll / @mraible - I'll provide a small sample very soon. The Log4J issue has kept me busy the last few days :-)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 15, 2021
@snicoll snicoll removed the status: feedback-provided Feedback has been provided label Dec 16, 2021
@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Dec 16, 2021
@ivangfr
Copy link

ivangfr commented Dec 17, 2021

Hi, I am facing the same problem

Steps

git clone https://github.com/ivangfr/springboot-caching-neo4j.git
cd springboot-caching-neo4j
git checkout project-update
  • To reproduce by running unit and integration tests

    ./mvnw clean verify --projects restaurant-api
    
  • To reproduce when trying to build the Docker native image

    ./mvnw clean spring-boot:build-image --projects restaurant-api -DskipTests
    

    P.S. It's weird why integration tests are staring even asking to skip the tests

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 17, 2021
@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Dec 17, 2021
@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 20, 2021

@ivangfr Your project is using Mockito which is unsupported for now, see #1343 and #1063 related issues.

@AndersClausen Sinec #1343 is now fixed in Spring Native 0.11.1-SNAPSHOT, feel free to try your use case generating this error with it. If you see a No qualifying bean of type 'org.springframework.boot.test.mock.mockito.MockitoPostProcessor' error, it is Mockito and this issue can be closed as a duplicate. If not, please share a repro.

@snicoll
Copy link
Contributor

snicoll commented Dec 20, 2021

For Spring MVC, I had to exclude Mockito and then delete the tests for ./mvnw package -Pnative,prod -DskipTests to work.

@mraible mockito on the classpath shouldn't be an issue. You can put it again with your deleted tests and it shouldn't make any difference.

For Spring WebFlux, I have to do neither and the same command works.

Using mockito manually in the test perhaps? (rather than @MockBean or something that would trigger Spring Boot's support for Mockito. Did this command ran your tests in a native image? I'd be surprised considering that Mockito isn't supported at all.

@sdeleuze
Copy link
Contributor

With 0.11.1-SNAPSHOT, meaningful error messages are now provided when @MockBean or @SpyBean are used.

@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Dec 24, 2021
@sdeleuze sdeleuze closed this as completed Jan 3, 2022
@sdeleuze sdeleuze removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue labels Jan 3, 2022
@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 3, 2022

Closing this issue due to lack of feedback and related fix via #1343.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

6 participants