Skip to content

Commit 3e85c5c

Browse files
author
Christian Wimmer
committed
Disallow --initialize-at-build-time without arguments
1 parent beba41a commit 3e85c5c

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

substratevm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This changelog summarizes major changes to GraalVM Native Image.
55
## Version 23.0.0
66
* (GR-40187) Report invalid use of SVM specific classes on image class- or module-path as error. As a temporary workaround, -H:+TolerateBuilderClassesOnImageClasspath allows turning the error into a warning.
77
* (GR-41196) Provide `.debug.svm.imagebuild.*` sections that contain build options and properties used in the build of the image.
8+
* (GR-41978) Disallow `--initialize-at-build-time` without arguments. As a temporary workaround, `-H:+AllowDeprecatedInitializeAllClassesAtBuildTime` allows turning this error into a warning.
89

910
## Version 22.3.0
1011
* (GR-35721) Remove old build output style and the `-H:±BuildOutputUseNewStyle` option.

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ private static class InitializationValueEager extends InitializationValueTransfo
9191
@Option(help = "A comma-separated list of classes appended with their initialization strategy (':build_time', ':rerun', or ':run_time')", type = OptionType.User)//
9292
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> ClassInitialization = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings());
9393

94+
@Option(help = "Instead of abort, only warn if --initialize-at-build-time= is used.", type = OptionType.Debug)//
95+
public static final HostedOptionKey<Boolean> AllowDeprecatedInitializeAllClassesAtBuildTime = new HostedOptionKey<>(false);
96+
9497
@Option(help = "Prints class initialization info for all classes detected by analysis.", type = OptionType.Debug)//
9598
public static final HostedOptionKey<Boolean> PrintClassInitialization = new HostedOptionKey<>(false);
9699

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/InitKind.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
*/
2525
package com.oracle.svm.hosted.classinitialization;
2626

27-
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsMode;
28-
2927
import java.util.Arrays;
3028
import java.util.Optional;
3129
import java.util.function.Consumer;
3230

3331
import org.graalvm.collections.Pair;
3432

3533
import com.oracle.svm.core.option.OptionOrigin;
34+
import com.oracle.svm.core.option.SubstrateOptionsParser;
35+
import com.oracle.svm.core.util.UserError;
3636

3737
/**
3838
* The initialization kind for a class. The order of the enum values matters, {@link #max} depends
@@ -71,12 +71,17 @@ Consumer<String> stringConsumer(ClassInitializationSupport support, OptionOrigin
7171
return name -> support.rerunInitialization(name, reason(origin, name));
7272
} else {
7373
return name -> {
74-
if (name.equals("") && !DiagnosticsMode.getValue()) {
75-
System.err.println(
76-
"--initialize-at-build-time without arguments has been deprecated when not using --diagnostics-mode. With GraalVM 22.0.0" +
77-
" --initialize-at-build-time will only work with --diagnostics-mode for debugging purposes.\n" +
78-
"The reason for deprecation is that --initalize-at-build-time does not compose, i.e., a single library can make assumptions that the whole classpath can be safely initialized at build time;" +
79-
" that assumption is often incorrect.");
74+
if (name.equals("") && !origin.commandLineLike()) {
75+
String msg = "--initialize-at-build-time without arguments is not allowed." + System.lineSeparator() +
76+
"Origin of the option: " + origin + System.lineSeparator() +
77+
"The reason for deprecation is that --initalize-at-build-time does not compose, i.e., a single library can make assumptions that the whole classpath can be safely initialized at build time;" +
78+
" that assumption is often incorrect.";
79+
if (ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime.getValue()) {
80+
System.err.println("Warning: " + msg);
81+
} else {
82+
throw UserError.abort("%s%nAs a temporary workaround, %s allows turning this error into a warning.", msg,
83+
SubstrateOptionsParser.commandArgument(ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime, "+"));
84+
}
8085
}
8186
support.initializeAtBuildTime(name, reason(origin, name));
8287
};

0 commit comments

Comments
 (0)