From d2218ae8b305e2a0afaacc516259940e06a8a141 Mon Sep 17 00:00:00 2001 From: Nizar Benalla Date: Tue, 31 Mar 2026 13:22:51 +0100 Subject: [PATCH] -empty option values cause jextract to crash -issue an error --- src/main/java/org/openjdk/jextract/JextractTool.java | 6 +++++- .../test/toolprovider/JextractToolProviderTest.java | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openjdk/jextract/JextractTool.java b/src/main/java/org/openjdk/jextract/JextractTool.java index 4f3c92a0..975d7089 100644 --- a/src/main/java/org/openjdk/jextract/JextractTool.java +++ b/src/main/java/org/openjdk/jextract/JextractTool.java @@ -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 @@ -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) == '-') { diff --git a/test/testng/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java b/test/testng/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java index 68dbcc85..b92e51d9 100644 --- a/test/testng/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java +++ b/test/testng/org/openjdk/jextract/test/toolprovider/JextractToolProviderTest.java @@ -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 @@ -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
"); + } + // error for non-existent args file @Test public void testNonExistentArgsFile() {