Skip to content

Commit

Permalink
Disallow --initialize-at-build-time without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Wimmer committed Oct 26, 2022
1 parent 43c74c3 commit 8ad5d4e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This changelog summarizes major changes to GraalVM Native Image.
## Version 23.0.0
* (GR-40187) Report invalid use of SVM specific classes on image class- or module-path as error. As a temporary workaround, `-H:+AllowDeprecatedBuilderClassesOnImageClasspath` allows turning the error into a warning.
* (GR-41196) Provide `.debug.svm.imagebuild.*` sections that contain build options and properties used in the build of the image.
* (GR-41978) Disallow `--initialize-at-build-time` without arguments. As a temporary workaround, `-H:+AllowDeprecatedInitializeAllClassesAtBuildTime` allows turning this error into a warning.

## Version 22.3.0
* (GR-35721) Remove old build output style and the `-H:±BuildOutputUseNewStyle` option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ private static class InitializationValueEager extends InitializationValueTransfo
@Option(help = "A comma-separated list of classes appended with their initialization strategy (':build_time', ':rerun', or ':run_time')", type = OptionType.User)//
public static final HostedOptionKey<LocatableMultiOptionValue.Strings> ClassInitialization = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings());

@Option(help = "Instead of abort, only warn if --initialize-at-build-time= is used.", type = OptionType.Debug)//
public static final HostedOptionKey<Boolean> AllowDeprecatedInitializeAllClassesAtBuildTime = new HostedOptionKey<>(false);

@Option(help = "Prints class initialization info for all classes detected by analysis.", type = OptionType.Debug)//
public static final HostedOptionKey<Boolean> PrintClassInitialization = new HostedOptionKey<>(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
*/
package com.oracle.svm.hosted.classinitialization;

import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsMode;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;

import org.graalvm.collections.Pair;

import com.oracle.svm.core.option.OptionOrigin;
import com.oracle.svm.core.option.SubstrateOptionsParser;
import com.oracle.svm.core.util.UserError;

/**
* The initialization kind for a class. The order of the enum values matters, {@link #max} depends
Expand Down Expand Up @@ -71,12 +71,17 @@ Consumer<String> stringConsumer(ClassInitializationSupport support, OptionOrigin
return name -> support.rerunInitialization(name, reason(origin, name));
} else {
return name -> {
if (name.equals("") && !DiagnosticsMode.getValue()) {
System.err.println(
"--initialize-at-build-time without arguments has been deprecated when not using --diagnostics-mode. With GraalVM 22.0.0" +
" --initialize-at-build-time will only work with --diagnostics-mode for debugging purposes.\n" +
"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;" +
" that assumption is often incorrect.");
if (name.equals("") && !origin.commandLineLike()) {
String msg = "--initialize-at-build-time without arguments is not allowed." + System.lineSeparator() +
"Origin of the option: " + origin + System.lineSeparator() +
"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;" +
" that assumption is often incorrect.";
if (ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime.getValue()) {
System.out.println("Warning: " + msg);
} else {
throw UserError.abort("%s%nAs a workaround, %s allows turning this error into a warning. Note that this option is deprecated and will be removed in a future version.", msg,
SubstrateOptionsParser.commandArgument(ClassInitializationOptions.AllowDeprecatedInitializeAllClassesAtBuildTime, "+"));
}
}
support.initializeAtBuildTime(name, reason(origin, name));
};
Expand Down

0 comments on commit 8ad5d4e

Please sign in to comment.