Skip to content

Commit

Permalink
Annotate some java.net classes, mostly related to cookies.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk committed Nov 12, 2024
1 parent 457b292 commit 0163788
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
13 changes: 6 additions & 7 deletions src/java.base/share/classes/java/net/CookieHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@

package java.net;

import org.checkerframework.checker.interning.qual.UsesObjectEquals;
import org.checkerframework.framework.qual.AnnotatedFor;

import java.util.Map;
import java.util.List;
import java.io.IOException;
import sun.security.util.SecurityConstants;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A CookieHandler object provides a callback mechanism to hook up a
Expand All @@ -53,8 +52,8 @@
* @author Yingxian Wang
* @since 1.5
*/
@AnnotatedFor({"interning"})
public abstract @UsesObjectEquals class CookieHandler {
@NullMarked
public abstract class CookieHandler {
/**
* Constructor for subclasses to call.
*/
Expand All @@ -79,7 +78,7 @@ public CookieHandler() {}
* {@link NetPermission}{@code ("getCookieHandler")}
* @see #setDefault(CookieHandler)
*/
public static synchronized CookieHandler getDefault() {
public static synchronized @Nullable CookieHandler getDefault() {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
Expand All @@ -100,7 +99,7 @@ public static synchronized CookieHandler getDefault() {
* {@link NetPermission}{@code ("setCookieHandler")}
* @see #getDefault()
*/
public static synchronized void setDefault(CookieHandler cHandler) {
public static synchronized void setDefault(@Nullable CookieHandler cHandler) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
Expand Down
9 changes: 6 additions & 3 deletions src/java.base/share/classes/java/net/CookieManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.Comparator;
import java.io.IOException;
import sun.util.logging.PlatformLogger;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* CookieManager provides a concrete implementation of {@link CookieHandler},
Expand Down Expand Up @@ -114,6 +116,7 @@
* @author Edward Wang
* @since 1.6
*/
@NullMarked
public class CookieManager extends CookieHandler
{
/* ---------------- Fields -------------- */
Expand Down Expand Up @@ -149,8 +152,8 @@ public CookieManager() {
* if {@code null}, ACCEPT_ORIGINAL_SERVER will
* be used.
*/
public CookieManager(CookieStore store,
CookiePolicy cookiePolicy)
public CookieManager(@Nullable CookieStore store,
@Nullable CookiePolicy cookiePolicy)
{
// use default cookie policy if not specify one
policyCallback = (cookiePolicy == null) ? CookiePolicy.ACCEPT_ORIGINAL_SERVER
Expand All @@ -177,7 +180,7 @@ public CookieManager(CookieStore store,
* @param cookiePolicy the cookie policy. Can be {@code null}, which
* has no effects on current cookie policy.
*/
public void setCookiePolicy(CookiePolicy cookiePolicy) {
public void setCookiePolicy(@Nullable CookiePolicy cookiePolicy) {
if (cookiePolicy != null) policyCallback = cookiePolicy;
}

Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/net/CookiePolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package java.net;

import org.jspecify.annotations.NullMarked;

/**
* CookiePolicy implementations decide which cookies should be accepted
* and which should be rejected. Three pre-defined policy implementations
Expand All @@ -35,6 +37,7 @@
* @author Edward Wang
* @since 1.6
*/
@NullMarked
public interface CookiePolicy {
/**
* One pre-defined policy which accepts all cookies.
Expand Down
28 changes: 17 additions & 11 deletions src/java.base/share/classes/java/net/HttpCookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package java.net;

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;

import java.util.List;
Expand Down Expand Up @@ -60,6 +62,7 @@
* @author Edward Wang
* @since 1.6
*/
@NullMarked
public final class HttpCookie implements Cloneable {
// ---------------- Fields --------------

Expand Down Expand Up @@ -140,6 +143,7 @@ public final class HttpCookie implements Cloneable {
* @see #setValue
* @see #setVersion
*/
@NullUnmarked // TODO(cpovirk): Should `value` be @Nullable?
public HttpCookie(String name, String value) {
this(name, value, null /*header*/);
}
Expand Down Expand Up @@ -262,7 +266,7 @@ public boolean hasExpired() {
*
* @see #getComment
*/
public void setComment(String purpose) {
public void setComment(@Nullable String purpose) {
comment = purpose;
}

Expand All @@ -274,7 +278,7 @@ public void setComment(String purpose) {
*
* @see #setComment
*/
public String getComment() {
public @Nullable String getComment() {
return comment;
}

Expand All @@ -288,7 +292,7 @@ public String getComment() {
*
* @see #getCommentURL
*/
public void setCommentURL(String purpose) {
public void setCommentURL(@Nullable String purpose) {
commentURL = purpose;
}

Expand All @@ -301,7 +305,7 @@ public void setCommentURL(String purpose) {
*
* @see #setCommentURL
*/
public String getCommentURL() {
public @Nullable String getCommentURL() {
return commentURL;
}

Expand Down Expand Up @@ -339,7 +343,7 @@ public boolean getDiscard() {
*
* @see #getPortlist
*/
public void setPortlist(String ports) {
public void setPortlist(@Nullable String ports) {
portlist = ports;
}

Expand All @@ -350,7 +354,7 @@ public void setPortlist(String ports) {
*
* @see #setPortlist
*/
public String getPortlist() {
public @Nullable String getPortlist() {
return portlist;
}

Expand All @@ -370,7 +374,7 @@ public String getPortlist() {
*
* @see #getDomain
*/
public void setDomain(String pattern) {
public void setDomain(@Nullable String pattern) {
if (pattern != null)
domain = pattern.toLowerCase(Locale.ROOT);
else
Expand All @@ -385,7 +389,7 @@ public void setDomain(String pattern) {
*
* @see #setDomain
*/
public String getDomain() {
public @Nullable String getDomain() {
return domain;
}

Expand Down Expand Up @@ -442,7 +446,7 @@ public long getMaxAge() {
*
* @see #getPath
*/
public void setPath(String uri) {
public void setPath(@Nullable String uri) {
path = uri;
}

Expand All @@ -455,7 +459,7 @@ public void setPath(String uri) {
*
* @see #setPath
*/
public String getPath() {
public @Nullable String getPath() {
return path;
}

Expand Down Expand Up @@ -514,6 +518,7 @@ public String getName() {
*
* @see #getValue
*/
@NullUnmarked // TODO(cpovirk): Should `newValue` be @Nullable?
public void setValue(String newValue) {
value = newValue;
}
Expand All @@ -525,6 +530,7 @@ public void setValue(String newValue) {
*
* @see #setValue
*/
@NullUnmarked // TODO(cpovirk): Should the return type be @Nullable?
public String getValue() {
return value;
}
Expand Down Expand Up @@ -644,7 +650,7 @@ public void setHttpOnly(boolean httpOnly) {
*
* @return {@code true} if they domain-matches; {@code false} if not
*/
public static boolean domainMatches(String domain, String host) {
public static boolean domainMatches(@Nullable String domain, @Nullable String host) {
if (domain == null || host == null)
return false;

Expand Down
3 changes: 2 additions & 1 deletion src/java.base/share/classes/java/net/URISyntaxException.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package java.net;

import org.jspecify.annotations.NullMarked;

/**
* Checked exception thrown to indicate that a string could not be parsed as a
Expand All @@ -34,7 +35,7 @@
* @see URI
* @since 1.4
*/

@NullMarked
public class URISyntaxException
extends Exception
{
Expand Down

0 comments on commit 0163788

Please sign in to comment.