1
1
/*
2
- * Copyright (c) 2023 Oracle and/or its affiliates.
2
+ * Copyright (c) 2023, 2024 Oracle and/or its affiliates.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -290,9 +290,10 @@ public static Header create(String name, long value) {
290
290
* Create a new header. This header is considered unchanging and not sensitive.
291
291
*
292
292
* @param name name of the header
293
- * @param values values of the header
293
+ * @param values values of the header, must contain at least one value (which may be an empty String)
294
294
* @return a new header
295
295
* @see #create(io.helidon.http.HeaderName, boolean, boolean, String...)
296
+ * @throws java.lang.IllegalArgumentException in case the collection is empty
296
297
*/
297
298
public static Header create (HeaderName name , String ... values ) {
298
299
if (values .length == 0 ) {
@@ -305,9 +306,10 @@ public static Header create(HeaderName name, String... values) {
305
306
* Create a new header. This header is considered unchanging and not sensitive.
306
307
*
307
308
* @param name name of the header
308
- * @param values values of the header
309
+ * @param values values of the header, must contain at least one value (which may be an empty String)
309
310
* @return a new header
310
311
* @see #create(io.helidon.http.HeaderName, boolean, boolean, String...)
312
+ * @throws java.lang.IllegalArgumentException in case the collection is empty
311
313
*/
312
314
public static Header create (String name , String ... values ) {
313
315
return create (HeaderNames .create (name ), values );
@@ -317,21 +319,26 @@ public static Header create(String name, String... values) {
317
319
* Create a new header. This header is considered unchanging and not sensitive.
318
320
*
319
321
* @param name name of the header
320
- * @param values values of the header
322
+ * @param values values of the header, must contain at least one value (which may be an empty String)
321
323
* @return a new header
322
324
* @see #create(io.helidon.http.HeaderName, boolean, boolean, String...)
325
+ * @throws java.lang.IllegalArgumentException in case the collection is empty
323
326
*/
324
327
public static Header create (HeaderName name , Collection <String > values ) {
328
+ if (values .isEmpty ()) {
329
+ throw new IllegalArgumentException ("Cannot create a header without a value. Header: " + name );
330
+ }
325
331
return new HeaderValueList (name , false , false , values );
326
332
}
327
333
328
334
/**
329
335
* Create a new header. This header is considered unchanging and not sensitive.
330
336
*
331
337
* @param name name of the header
332
- * @param values values of the header
338
+ * @param values values of the header, must contain at least one value (which may be an empty String)
333
339
* @return a new header
334
340
* @see #create(io.helidon.http.HeaderName, boolean, boolean, String...)
341
+ * @throws java.lang.IllegalArgumentException in case the collection is empty
335
342
*/
336
343
public static Header create (String name , Collection <String > values ) {
337
344
return create (HeaderNames .create (name ), values );
0 commit comments