GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(java): initialize classes at build-time to fix Native Image compilation by mpeddada1 · Pull Request #874 · googleapis/java-storage-nio

This repository was archived by the owner on Jun 2, 2026. It is now read-only.

Conversation

@mpeddada1

@mpeddada1 mpeddada1 commented Mar 29, 2022

Copy link
Copy Markdown
Contributor

Using META-INF/services with Native Image compilation causes the FileSystemProvider class to be initialized at build time. This causes com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider and a couple of unexpected classes that are referenced to also be initialized at build time.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mpeddada1
fix(java): initialize classes at build-time to Native Image support i…
fddce03
…ssues
@mpeddada1
mpeddada1 requested review from a team March 29, 2022 14:56
@product-auto-label product-auto-label Bot added the api: storage Issues related to the googleapis/java-storage-nio API. label Mar 29, 2022
suztomo
suztomo reviewed Mar 29, 2022
View reviewed changes
Comment thread ...in/resources/META-INF/native-image/com/google/cloud/google-cloud-nio/native-image.properties Outdated
Comment on lines +3 to +4
# CloudStorageFileSystemProvider and all the sub-classes referenced by
# this class also being initialized at build time.

@suztomo suztomo Mar 29, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for static fields or static initializers are needed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mpeddada1 mpeddada1 Mar 30, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly updated the comment here. Let me know if this sounds okay to you? Explored the code a little further to double check what's happening: The initialization of classes stems from CloudStorageFileSystemProvider which causes StorageOptions and as a result StorageOptionsUtil to be initialized at build time.

java-storage-nio/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Line 96 in 004ab8c

private static StorageOptions futureStorageOptions = StorageOptionsUtil.getDefaultInstance();

Looks like this seems to be the case in the reproducer as well where when we create a new class MyOptions and instantiate it in MySampleFileSystemProvider, MyOptions ends up getting initialized at build time.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
suztomo
suztomo reviewed Mar 29, 2022
View reviewed changes
Comment thread ...in/resources/META-INF/native-image/com/google/cloud/google-cloud-nio/native-image.properties
com.google.cloud.storage.StorageOptions,\
com.google.cloud.storage.DefaultStorageRetryStrategy,\
com.google.api.client.http.OpenCensusUtils,\
com.google.api.client.http.GenericUrl,\

@suztomo suztomo Mar 29, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm curious about how you get the list)

If we don't have this GenericUrl line here, what kind of error do you get?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mpeddada1 mpeddada1 Mar 30, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing GenericUrl results in:

Error: Classes that should be initialized at run time got initialized during image building:
 com.google.api.client.http.GenericUrl was unintentionally initialized at build time. To see why com.google.api.client.http.GenericUrl got initialized use --trace-class-initialization=com.google.api.client.http.GenericUrl

And removing all the other classes results in a similar error for the following classes:

--trace-class-initialization=com.google.api.client.json.gson.GsonParser$1,io.opencensus.trace.Tracing,io.opencensus.trace.EndSpanOptions,com.google.api.client.http.HttpRequest,org.threeten.bp.Duration,com.google.api.client.http.javanet.NetHttpTransport,com.google.auth.oauth2.OAuth2Utils,com.google.cloud.storage.StorageOptions,io.opencensus.contrib.http.util.CloudTraceFormat,com.google.auth.oauth2.DefaultCredentialsProvider,io.opencensus.trace.Status,io.opencensus.trace.AutoValue_EndSpanOptions,com.google.cloud.storage.DefaultStorageRetryStrategy,com.google.api.client.http.OpenCensusUtils,com.google.cloud.storage.StorageException,com.google.gson.stream.JsonReader,com.google.auth.oauth2.OAuth2Credentials,com.google.api.client.util.DateTime,com.google.api.client.util.escape.PercentEscaper,com.google.cloud.ExceptionHandler,io.opencensus.trace.BlankSpan,io.opencensus.trace.SpanContext,com.google.api.client.json.JsonParser$1,com.google.api.client.http.HttpTransport,com.google.api.client.http.HttpMediaType,com.google.auth.oauth2.GoogleCredentials,com.google.common.collect.RegularImmutableMap,io.opencensus.trace.Span,com.google.api.client.http.GenericUrl,com.google.cloud.ServiceOptions,com.google.api.client.util.Data,com.google.api.client.util.escape.CharEscapers,com.google.cloud.PlatformInformation

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@suztomo suztomo Mar 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thank you for checking.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
meltsufin
meltsufin approved these changes Mar 29, 2022
View reviewed changes
@mpeddada1
update comment in native-image.properties
fe9fd7b
suztomo
suztomo approved these changes Mar 30, 2022
View reviewed changes
Comment thread ...in/resources/META-INF/native-image/com/google/cloud/google-cloud-nio/native-image.properties
com.google.cloud.storage.StorageOptions,\
com.google.cloud.storage.DefaultStorageRetryStrategy,\
com.google.api.client.http.OpenCensusUtils,\
com.google.api.client.http.GenericUrl,\

@suztomo suztomo Mar 30, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thank you for checking.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead suggested changes Mar 30, 2022
View reviewed changes

@BenWhitehead BenWhitehead left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add some additional classes, not sure if that's unexpected

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...in/resources/META-INF/native-image/com/google/cloud/google-cloud-nio/native-image.properties Resolved

Uh oh!

There was an error while loading. Please reload this page.

mpeddada1 added 2 commits March 30, 2022 15:16
@mpeddada1
Merge branch 'main' of github.com:googleapis/java-storage-nio into na…
620c0c8
…tive-image-tests
@mpeddada1
add missing classes
3ac88f0
BenWhitehead
BenWhitehead approved these changes Mar 30, 2022
View reviewed changes
@BenWhitehead
BenWhitehead merged commit df905cb into main Mar 30, 2022
@BenWhitehead
BenWhitehead deleted the native-image-tests branch March 30, 2022 20:39
@release-please release-please Bot mentioned this pull request Mar 30, 2022
chore(main): release 0.123.28 #879
Merged
gcf-merge-on-green Bot pushed a commit that referenced this pull request Apr 19, 2022
@release-please
chore(main): release 0.123.28 (#879)
29707f5
🤖 I have created a release *beep* *boop*
---


### [0.123.28](v0.123.27...v0.123.28) (2022-04-18)


### Bug Fixes

* **native:** initialize classes at build-time to fix Native Image compilation ([#874](#874)) ([df905cb](df905cb))
* **test:** replace HashMap with ConcurrentHashMap to avoid ConcurrentModificatio… ([#883](#883)) ([d2fe2a0](d2fe2a0))


### Dependencies

* update dependency com.google.apis:google-api-services-storage to v1-rev20220401-1.32.1 ([#881](#881)) ([a598199](a598199))
* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.10.0 ([#884](#884)) ([c08f115](c08f115))
* update dependency com.google.cloud:google-cloud-storage to v2.6.0 ([#878](#878)) ([0bd1985](0bd1985))
* update dependency com.google.cloud:google-cloud-storage to v2.6.1 ([#885](#885)) ([cf24525](cf24525))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
suztomo pushed a commit to googleapis/google-cloud-java that referenced this pull request Mar 30, 2026
@release-please
chore(main): release 0.123.28 (#879)
677ef62
🤖 I have created a release *beep* *boop*
---


### [0.123.28](googleapis/java-storage-nio@v0.123.27...v0.123.28) (2022-04-18)


### Bug Fixes

* **native:** initialize classes at build-time to fix Native Image compilation ([#874](googleapis/java-storage-nio#874)) ([22f1464](googleapis/java-storage-nio@22f1464))
* **test:** replace HashMap with ConcurrentHashMap to avoid ConcurrentModificatio… ([#883](googleapis/java-storage-nio#883)) ([31f823c](googleapis/java-storage-nio@31f823c))


### Dependencies

* update dependency com.google.apis:google-api-services-storage to v1-rev20220401-1.32.1 ([#881](googleapis/java-storage-nio#881)) ([4f89adc](googleapis/java-storage-nio@4f89adc))
* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.10.0 ([#884](googleapis/java-storage-nio#884)) ([9d06c27](googleapis/java-storage-nio@9d06c27))
* update dependency com.google.cloud:google-cloud-storage to v2.6.0 ([#878](googleapis/java-storage-nio#878)) ([425f3de](googleapis/java-storage-nio@425f3de))
* update dependency com.google.cloud:google-cloud-storage to v2.6.1 ([#885](googleapis/java-storage-nio#885)) ([8329458](googleapis/java-storage-nio@8329458))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
lqiu96 pushed a commit to googleapis/google-cloud-java that referenced this pull request Apr 1, 2026
@release-please
chore(main): release 0.123.28 (#879)
f39b482
🤖 I have created a release *beep* *boop*
---


### [0.123.28](googleapis/java-storage-nio@v0.123.27...v0.123.28) (2022-04-18)


### Bug Fixes

* **native:** initialize classes at build-time to fix Native Image compilation ([#874](googleapis/java-storage-nio#874)) ([22f1464](googleapis/java-storage-nio@22f1464))
* **test:** replace HashMap with ConcurrentHashMap to avoid ConcurrentModificatio… ([#883](googleapis/java-storage-nio#883)) ([31f823c](googleapis/java-storage-nio@31f823c))


### Dependencies

* update dependency com.google.apis:google-api-services-storage to v1-rev20220401-1.32.1 ([#881](googleapis/java-storage-nio#881)) ([4f89adc](googleapis/java-storage-nio@4f89adc))
* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.10.0 ([#884](googleapis/java-storage-nio#884)) ([9d06c27](googleapis/java-storage-nio@9d06c27))
* update dependency com.google.cloud:google-cloud-storage to v2.6.0 ([#878](googleapis/java-storage-nio#878)) ([425f3de](googleapis/java-storage-nio@425f3de))
* update dependency com.google.cloud:google-cloud-storage to v2.6.1 ([#885](googleapis/java-storage-nio#885)) ([8329458](googleapis/java-storage-nio@8329458))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

3 more reviewers
@BenWhitehead BenWhitehead BenWhitehead approved these changes
@suztomo suztomo suztomo approved these changes
@meltsufin meltsufin meltsufin approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: storage Issues related to the googleapis/java-storage-nio API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@mpeddada1 @suztomo @BenWhitehead @meltsufin
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.