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

Remove remaining build time initialization (logging, hibernate validator, netty, etc.) #927

Closed
leorric opened this issue Jul 23, 2021 · 12 comments
Assignees
Labels
for: external-project For an external project and not something we can fix type: compatibility Native image compatibility issue

Comments

@leorric
Copy link

leorric commented Jul 23, 2021

I tried to build image for my project using mvn spring-boot:build-image and it failed. Log snippet as following.

Error: Classes that should be initialized at run time got initialized during image building:
[INFO] [creator] org.apache.commons.logging.impl.SLF4JLocationAwareLog was unintentionally initialized at build time. To see why org.apache.commons.logging.impl.SLF4JLocationAwareLog got initialized use --trace-class-initialization=org.apache.commons.logging.impl.SLF4JLocationAwareLog
[INFO] [creator]
[INFO] [creator] Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO] [creator] Error: Image build request failed with exit status 1
[INFO] [creator] unable to invoke layer creator
[INFO] [creator] unable to contribute native-image layer

My question is :

  1. How can I trace class initialization with Spring Boot Buildpacks support. I mean because this is not maven command option, I cannot use mvn spring-boot:build-image --trace-class-initialization.
  2. How to solve this problem , specifically how can I avoid build time initialization , any hint will be appreciated.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 23, 2021
@lhstack
Copy link

lhstack commented Jul 24, 2021

I also encountered this problem when I added logback.xml to the Resource directory and the problem was restored when I deleted the logback.xml file

@sdeleuze sdeleuze added type: question A question and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 26, 2021
@sdeleuze sdeleuze changed the title Build failed with error information "Classes that should be initialized at run time got initialized during image building" Remove remaining build time initialization (logging, hibernate validator, etc.) Jul 26, 2021
@sdeleuze sdeleuze added type: compatibility Native image compatibility issue and removed type: question A question labels Jul 26, 2021
@sdeleuze sdeleuze added this to the Backlog milestone Jul 26, 2021
@sdeleuze
Copy link
Contributor

With Buildpacks --trace-class-initialization should be added via BP_NATIVE_IMAGE_BUILD_ARGUMENTS as described in this section.

We are working to remove default build time initialization, and indeed adding logback.xml triggers this issue as well. I have turned this issue into a global "Remove remaining build time initialization" one.

@sdeleuze sdeleuze self-assigned this Jul 26, 2021
@sdeleuze sdeleuze changed the title Remove remaining build time initialization (logging, hibernate validator, etc.) Remove remaining build time initialization (logging, hibernate validator, netty, etc.) Jul 26, 2021
@sdeleuze sdeleuze modified the milestones: Backlog, 0.12.0 Jul 26, 2021
@phejl
Copy link

phejl commented Jul 27, 2021

I'm not sure but isn't it at least in case of the trigger duplicate of #625

@sdeleuze
Copy link
Contributor

@phejl Sorry but not sure to fully understand your comment. What i can say is that solving this issue should help a lot for #625.

@phejl
Copy link

phejl commented Jul 27, 2021

@sdeleuze Aha, I'm sorry. I missed your comment #927 (comment) - that's what I tried to express.

@sdeleuze sdeleuze modified the milestones: 0.12.0, Backlog Aug 25, 2021
@hdeadman
Copy link
Contributor

I am getting a similar error (using latest plugin from main) although it is for object instantiation instead of class initialization, for jcl-over-slf4j class SLF4JLocationAwareLog. If I am using the gradle springAot plugin, how do I specify --trace-object-instantiation? The documentation says how to do it when using buildpacks and with the maven plugin but I don't see how to do it when using gradle.

Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: 
No instances of org.apache.commons.logging.impl.SLF4JLocationAwareLog are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use 
--trace-object-instantiation=org.apache.commons.logging.impl.SLF4JLocationAwareLog.
        at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.checkImageHeapInstance(ClassInitializationFeature.java:134)

@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 6, 2021

You can use NativeHint(options = "--trace-object-instantiation=org.apache.commons.logging.impl.SLF4JLocationAwareLog"). Feel free to comment if you think we should update default initialization hint based on your findings.

@sdeleuze sdeleuze modified the milestones: Backlog, 0.11.3 Jan 17, 2022
@sdeleuze
Copy link
Contributor

We are progressing on that one, with a collaboration with GraalVM team on Netty, but that will take more time than expected so I bring back this one to the backlog.

@sdeleuze sdeleuze modified the milestones: 0.11.3, Backlog Feb 14, 2022
@nyakaz73
Copy link

Any resolve on the above i seem to be getting the same error

@nyakaz73
Copy link

[creator] [2/7] Performing analysis... [] (17.4s @ 1.60GB)
[creator] To see how the classes got initialized, use --trace-class-initialization=org.springframework.util.unit.DataSize
[creator] 6,948 (89.29%) of 7,781 classes reachable
[creator] 10,074 (71.60%) of 14,070 fields reachable
[creator] 33,053 (81.94%) of 40,339 methods reachable
[creator] 153 classes, 70 fields, and 1,256 methods registered for reflection
[creator] er:bootBuildImage
[creator] Error: Classes that should be initialized at run time got initialized during image building:
[creator] org.springframework.util.unit.DataSize was unintentionally initialized at build time. To see why org.springframework.util.unit.DataSize got initialized use --trace-class-initialization=org.springframework.util.unit.DataSize

@sdeleuze
Copy link
Contributor

@nyakaz73 Something is likely wrong with your setup since this is fixed out of the box by Spring Native for a long time. In the meantime, you can follow oracle/graal#4489 to see the proper resolution at GraalVM level.

@sdeleuze sdeleuze added the for: external-project For an external project and not something we can fix label Jan 2, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 2, 2023

Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details.

As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer.

Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3.

@sdeleuze sdeleuze closed this as completed Jan 2, 2023
@sdeleuze sdeleuze removed this from the Backlog milestone Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
for: external-project For an external project and not something we can fix type: compatibility Native image compatibility issue
Development

No branches or pull requests

7 participants