25
25
26
26
package java .net ;
27
27
28
+ import org .jspecify .annotations .NullMarked ;
29
+ import org .jspecify .annotations .NullUnmarked ;
28
30
import org .jspecify .annotations .Nullable ;
29
31
30
32
import java .util .List ;
60
62
* @author Edward Wang
61
63
* @since 1.6
62
64
*/
65
+ @ NullMarked
63
66
public final class HttpCookie implements Cloneable {
64
67
// ---------------- Fields --------------
65
68
@@ -140,6 +143,7 @@ public final class HttpCookie implements Cloneable {
140
143
* @see #setValue
141
144
* @see #setVersion
142
145
*/
146
+ @ NullUnmarked // TODO(cpovirk): Should `value` be @Nullable?
143
147
public HttpCookie (String name , String value ) {
144
148
this (name , value , null /*header*/ );
145
149
}
@@ -262,7 +266,7 @@ public boolean hasExpired() {
262
266
*
263
267
* @see #getComment
264
268
*/
265
- public void setComment (String purpose ) {
269
+ public void setComment (@ Nullable String purpose ) {
266
270
comment = purpose ;
267
271
}
268
272
@@ -274,7 +278,7 @@ public void setComment(String purpose) {
274
278
*
275
279
* @see #setComment
276
280
*/
277
- public String getComment () {
281
+ public @ Nullable String getComment () {
278
282
return comment ;
279
283
}
280
284
@@ -288,7 +292,7 @@ public String getComment() {
288
292
*
289
293
* @see #getCommentURL
290
294
*/
291
- public void setCommentURL (String purpose ) {
295
+ public void setCommentURL (@ Nullable String purpose ) {
292
296
commentURL = purpose ;
293
297
}
294
298
@@ -301,7 +305,7 @@ public void setCommentURL(String purpose) {
301
305
*
302
306
* @see #setCommentURL
303
307
*/
304
- public String getCommentURL () {
308
+ public @ Nullable String getCommentURL () {
305
309
return commentURL ;
306
310
}
307
311
@@ -339,7 +343,7 @@ public boolean getDiscard() {
339
343
*
340
344
* @see #getPortlist
341
345
*/
342
- public void setPortlist (String ports ) {
346
+ public void setPortlist (@ Nullable String ports ) {
343
347
portlist = ports ;
344
348
}
345
349
@@ -350,7 +354,7 @@ public void setPortlist(String ports) {
350
354
*
351
355
* @see #setPortlist
352
356
*/
353
- public String getPortlist () {
357
+ public @ Nullable String getPortlist () {
354
358
return portlist ;
355
359
}
356
360
@@ -370,7 +374,7 @@ public String getPortlist() {
370
374
*
371
375
* @see #getDomain
372
376
*/
373
- public void setDomain (String pattern ) {
377
+ public void setDomain (@ Nullable String pattern ) {
374
378
if (pattern != null )
375
379
domain = pattern .toLowerCase (Locale .ROOT );
376
380
else
@@ -385,7 +389,7 @@ public void setDomain(String pattern) {
385
389
*
386
390
* @see #setDomain
387
391
*/
388
- public String getDomain () {
392
+ public @ Nullable String getDomain () {
389
393
return domain ;
390
394
}
391
395
@@ -442,7 +446,7 @@ public long getMaxAge() {
442
446
*
443
447
* @see #getPath
444
448
*/
445
- public void setPath (String uri ) {
449
+ public void setPath (@ Nullable String uri ) {
446
450
path = uri ;
447
451
}
448
452
@@ -455,7 +459,7 @@ public void setPath(String uri) {
455
459
*
456
460
* @see #setPath
457
461
*/
458
- public String getPath () {
462
+ public @ Nullable String getPath () {
459
463
return path ;
460
464
}
461
465
@@ -514,6 +518,7 @@ public String getName() {
514
518
*
515
519
* @see #getValue
516
520
*/
521
+ @ NullUnmarked // TODO(cpovirk): Should `newValue` be @Nullable?
517
522
public void setValue (String newValue ) {
518
523
value = newValue ;
519
524
}
@@ -525,6 +530,7 @@ public void setValue(String newValue) {
525
530
*
526
531
* @see #setValue
527
532
*/
533
+ @ NullUnmarked // TODO(cpovirk): Should the return type be @Nullable?
528
534
public String getValue () {
529
535
return value ;
530
536
}
@@ -644,7 +650,14 @@ public void setHttpOnly(boolean httpOnly) {
644
650
*
645
651
* @return {@code true} if they domain-matches; {@code false} if not
646
652
*/
647
- public static boolean domainMatches (String domain , String host ) {
653
+ /*
654
+ * JSpecify: Passing null for either parameter seems likely to be at least suspicious. However,
655
+ * if we make the types non-null, we would change the null behavior under Kotlin from "return
656
+ * false" to "throw NullPointerException." And it's not clear whether any callers pass null in
657
+ * practice, even the one caller in the JDK, which passes cookie.getDomain() and uri.getHost(),
658
+ * both of which have nullable types.
659
+ */
660
+ public static boolean domainMatches (@ Nullable String domain , @ Nullable String host ) {
648
661
if (domain == null || host == null )
649
662
return false ;
650
663
0 commit comments