Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion src/main/java/org/openjdk/jextract/JextractTool.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -325,6 +325,10 @@ OptionSet parse(String[] args) {
i++; // consume value from next command line arg
} // else -DFOO like case. argValue already set

// do not allow empty argument values
if (argValue.isEmpty()) {
throw new OptionException("empty value for option: " + arg);
}
// do not allow argument value to start with '-'
// this will catch issues like "-l-lclang", "-l -t"
if (argValue.charAt(0) == '-') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -52,6 +52,15 @@ public void testVersion() {
runNoOuput("--version").checkSuccess();
}

// error for empty option value
@Test
public void testEmptyOptionValue() {
runNoOuput("-D", "", getInputFilePath("hello.h").toString())
.checkFailure(OPTION_ERROR)
.checkContainsOutput("empty value for option: -D")
.checkContainsOutput("Usage: jextract <options> <header file>");
}

// error for non-existent args file
@Test
public void testNonExistentArgsFile() {
Expand Down