Skip to content

Commit

Permalink
Make commandArgument() more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Nov 6, 2023
1 parent a52ea87 commit 48a2085
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
import java.util.function.Predicate;

import org.graalvm.collections.EconomicMap;
import jdk.graal.compiler.options.OptionDescriptor;
import jdk.graal.compiler.options.OptionDescriptors;
import jdk.graal.compiler.options.OptionKey;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

Expand All @@ -47,6 +44,10 @@
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.LogUtils;

import jdk.graal.compiler.options.OptionDescriptor;
import jdk.graal.compiler.options.OptionDescriptors;
import jdk.graal.compiler.options.OptionKey;

/**
* This class contains methods for parsing options and matching them against
* {@link OptionDescriptor}s.
Expand Down Expand Up @@ -178,14 +179,18 @@ public static String commandArgument(OptionKey<?> option, String value, String a
/* Ensure descriptor is loaded */
OptionDescriptor optionDescriptor = option.loadDescriptor();
Field field;
APIOption[] apiOptions;
try {
field = optionDescriptor.getDeclaringClass().getDeclaredField(optionDescriptor.getFieldName());
apiOptions = field.getAnnotationsByType(APIOption.class);
} catch (ReflectiveOperationException ex) {
throw VMError.shouldNotReachHere(ex);
/*
* Options whose fields cannot be looked up (e.g., due to stripped sources) cannot be
* API options by definition.
*/
apiOptions = new APIOption[0];
}

APIOption[] apiOptions = field.getAnnotationsByType(APIOption.class);

if (optionDescriptor.getOptionValueType() == Boolean.class) {
VMError.guarantee(value.equals("+") || value.equals("-"), "Boolean option value can be only + or -");
for (APIOption apiOption : apiOptions) {
Expand Down

0 comments on commit 48a2085

Please sign in to comment.