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

fix(java): initialize classes at build-time to fix Native Image compilation #874

Merged
merged 4 commits into from
Mar 30, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Using META-INF/services with Native Image compilation results in
# FileSystemProvider being initialized at build time. This results
# CloudStorageFileSystemProvider and some classes referenced by
# this class (for example, StorageOptions, StorageOptionsUtil,
# DefaultStorageRetryStrategy) being unexpectedly and recursively initialized at
# build time.
Args = --initialize-at-build-time=com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider,\
com.google.cloud.storage.contrib.nio.CloudStorageConfiguration,\
com.google.cloud.storage.contrib.nio.CloudStorageFileSystem,\
com.google.cloud.storage.contrib.nio.StorageOptionsUtil,\
com.google.cloud.storage.StorageException,\
com.google.cloud.storage.StorageOptions,\
com.google.cloud.storage.DefaultStorageRetryStrategy,\
com.google.api.client.http.OpenCensusUtils,\
com.google.api.client.http.GenericUrl,\
Copy link
Member

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?

Copy link
Contributor Author

@mpeddada1 mpeddada1 Mar 30, 2022

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

Copy link
Member

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.

com.google.api.client.http.HttpRequest,\
com.google.api.client.http.HttpMediaType,\
com.google.api.client.http.javanet.NetHttpTransport,\
com.google.api.client.util.Data,\
com.google.api.client.util.DateTime,\
com.google.auth.oauth2,\
io.opencensus.trace,\
com.google.api.client.util.escape.CharEscapers,\
com.google.api.client.util.escape.PercentEscaper,\
io.opencensus.contrib.http.util.CloudTraceFormat,\
io.grpc.Context,\
io.grpc.Context$LazyStorage,\
io.grpc.ThreadLocalContextStorage,\
com.google.common.cache.LocalCache,\
com.google.common.cache.CacheBuilder,\
com.google.common.math.IntMath$1,\
com.google.common.collect.RegularImmutableMap,\
com.google.gson.stream.JsonReader,\
com.google.api.client.json.gson.GsonParser$1,\
com.google.api.client.json.JsonParser$1,\
com.google.cloud.PlatformInformation,\
com.google.cloud.ExceptionHandler,\
org.threeten.bp.Duration
BenWhitehead marked this conversation as resolved.
Show resolved Hide resolved