Skip to content

Commit 7f83c75

Browse files
committed
Allow error reporting to get demoted to warning to work around non-compliant applications
1 parent adde8dc commit 7f83c75

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ def extra_image_build_argument(self, benchmark, args):
371371
'-H:EnableURLProtocols=http',
372372
'-H:NativeLinkerOption=-no-pie',
373373
'-H:-UseServiceLoaderFeature',
374+
'-H:+TolerateBuilderClassesOnImageClasspath', # needs to be removed once GR-41746 is fixed
374375
'--add-exports=org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED',
375376
'--add-exports=org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UNNAMED',
376377
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED',

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,4 +845,7 @@ public Boolean getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> v
845845
}
846846
};
847847

848+
@Option(help = "Instead of abort, only warn if image builder classes are found on the image class-path.", type = Debug)//
849+
public static final HostedOptionKey<Boolean> TolerateBuilderClassesOnImageClasspath = new HostedOptionKey<>(false);
850+
848851
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ public void reportBuilderClassesInApplication() {
819819
var destinationMap = builderURILocations.contains(classesEntries.getKey()) ? builderClasses : applicationClasses;
820820
destinationMap.put(classesEntries.getKey(), classesEntries.getValue());
821821
}
822+
boolean tolerateViolations = SubstrateOptions.TolerateBuilderClassesOnImageClasspath.getValue(parsedHostedOptions);
822823
MapCursor<URI, EconomicSet<String>> applicationClassesEntries = applicationClasses.getEntries();
823824
while (applicationClassesEntries.advance()) {
824825
var applicationClassContainer = applicationClassesEntries.getKey();
@@ -827,9 +828,13 @@ public void reportBuilderClassesInApplication() {
827828
while (builderClassesEntries.advance()) {
828829
var builderClassContainer = builderClassesEntries.getKey();
829830
if (builderClassesEntries.getValue().contains(applicationClass)) {
830-
throw UserError.abort("Class-path entry %s contains class %s. This class is part of the image builder itself (in %s) and must not be passed via -cp. " +
831-
"This can be caused by a fat-jar that illegally includes svm.jar (or graal-sdk.jar) due to its build-time dependency on it.%n",
831+
String message = String.format("Class-path entry %s contains class %s. This class is part of the image builder itself (in %s) and must not be passed via -cp.",
832832
applicationClassContainer, applicationClass, builderClassContainer);
833+
if (!tolerateViolations) {
834+
throw UserError.abort(message + " This can be caused by a fat-jar that illegally includes svm.jar (or graal-sdk.jar) due to its build-time dependency on it.%n");
835+
} else {
836+
System.out.println("Warning: " + message);
837+
}
833838
}
834839
}
835840
}

0 commit comments

Comments
 (0)