Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class BufferedInputStream extends FilterInputStream {
* indicator that this stream is closed. (The "in" field is also
* nulled out on close.)
*/
protected volatile byte[] buf;
protected volatile byte @Nullable [] buf;

/**
* The index one greater than the index of the last valid byte in
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/io/FilterInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class FilterInputStream extends InputStream {
/**
* The input stream to be filtered.
*/
protected volatile InputStream in;
protected volatile @Nullable InputStream in;

/**
* Creates a {@code FilterInputStream}
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ protected Package definePackage( String name, @Nullable String specTitle,
*
* @since 9
*/
public final Package getDefinedPackage(String name) {
public final @Nullable Package getDefinedPackage(String name) {
Objects.requireNonNull(name, "name cannot be null");

NamedPackage p = packages.get(name);
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/net/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ synchronized InetAddress getHostAddress() {
* or <CODE>null</CODE> if one does not exist
* @since 1.3
*/
public String getQuery() {
public @Nullable String getQuery() {
return query;
}

Expand All @@ -983,7 +983,7 @@ public String getPath() {
* <CODE>null</CODE> if one does not exist
* @since 1.3
*/
public String getUserInfo() {
public @Nullable String getUserInfo() {
return userInfo;
}

Expand All @@ -993,7 +993,7 @@ public String getUserInfo() {
* @return the authority part of this {@code URL}
* @since 1.3
*/
public String getAuthority() {
public @Nullable String getAuthority() {
return authority;
}

Expand Down Expand Up @@ -1062,7 +1062,7 @@ public String getFile() {
* @return the anchor (also known as the "reference") of this
* {@code URL}, or <CODE>null</CODE> if one does not exist
*/
public String getRef() {
public @Nullable String getRef() {
return ref;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import java.util.Objects;
import org.jspecify.annotations.Nullable;

/**
* This class is used as an opaque representation of cryptographic parameters.
Expand Down Expand Up @@ -420,7 +421,7 @@ public final byte[] getEncoded(String format) throws IOException
* @return a formatted string describing the parameters, or {@code null}
* if this parameter object has not been initialized.
*/
public final String toString() {
public final @Nullable String toString() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really ugly, as you note. It breaks behavioral subtyping, contradicting the contract from java.lang.Object#toString.
jspecify/jspecify#111 would say that this annotation should cause a distinct warning.
But as this is what the code is clearly doing, the annotation matches the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep :(

One note for anyone in the future who might be interested: It's not really fair of me to call this annotation "missing" in the way that the others are: This class is not @NullMarked, so JSpecify would say that the return type is unspecified. (Of course, I could hardly criticize a tool for still treating it as non-null, given everything you've said about toString().) Thus, the @Nullable annotation here is "missing" only in the sense that all unannotated code is "missing" tons of annotations. That is in contrast to the other edits I'm making, which are in null-marked classes, since those are changing types from non-null to nullable.

if (!this.initialized) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/regex/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public int end(String name) {
* or if the previous match operation failed
*/

public String group() {
public @Nullable String group() {
return group(0);
}

Expand Down
6 changes: 3 additions & 3 deletions src/java.desktop/share/classes/java/awt/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ void initializeFocusTraversalKeys() {
* Constructs a name for this component. Called by {@code getName}
* when the name is {@code null}.
*/
@Nullable String constructComponentName() {
String constructComponentName() {
return null; // For strict compliance with prior platform versions, a Component
// that doesn't set its name should return null from
// getName()
Expand All @@ -1003,7 +1003,7 @@ void initializeFocusTraversalKeys() {
* @see #setName
* @since 1.1
*/
public String getName() {
public @Nullable String getName() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see also adding @Nullable on the parameter of setName, but I didn't give it much thought.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would seem consistent to make the setName parameter @Nullable - the check for nameExplicitlySet helps to account for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks, I hadn't paid attention to the nameExplicitlySet check. That does suggest that upstream is at minimum resigned to supporting null :) Done.

if (name == null && !nameExplicitlySet) {
synchronized(getObjectLock()) {
if (name == null && !nameExplicitlySet)
Expand All @@ -1020,7 +1020,7 @@ public String getName() {
* @see #getName
* @since 1.1
*/
public void setName(String name) {
public void setName(@Nullable String name) {
String oldName;
synchronized(getObjectLock()) {
oldName = this.name;
Expand Down
4 changes: 2 additions & 2 deletions src/java.desktop/share/classes/java/awt/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -2668,7 +2668,7 @@ boolean isSameOrAncestorOf(Component comp, boolean allowChildren) {
* @see #getComponentAt
* @since 1.2
*/
public Component findComponentAt(int x, int y) {
public @Nullable Component findComponentAt(int x, int y) {
return findComponentAt(x, y, true);
}

Expand Down Expand Up @@ -2763,7 +2763,7 @@ private static Component getChildAt(Component comp, int x, int y,
* @see #getComponentAt
* @since 1.2
*/
public Component findComponentAt(Point p) {
public @Nullable Component findComponentAt(Point p) {
return findComponentAt(p.x, p.y);
}

Expand Down
10 changes: 5 additions & 5 deletions src/java.sql/share/classes/java/sql/ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ public interface ResultSet extends Wrapper, AutoCloseable {
* or {@code getBigDecimal(String columnLabel)}
*/
@Deprecated(since="1.2")
BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException;
@Nullable BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException;

/**
* Retrieves the value of the designated column in the current row
Expand Down Expand Up @@ -795,7 +795,7 @@ public interface ResultSet extends Wrapper, AutoCloseable {
* if a database access error occurs or this method is
* called on a closed result set
*/
java.io.InputStream getBinaryStream(String columnLabel)
java.io.@Nullable InputStream getBinaryStream(String columnLabel)
throws SQLException;


Expand Down Expand Up @@ -2493,7 +2493,7 @@ void updateObject(String columnLabel, @Nullable Object x, int scaleOrLength)
* this method
* @since 1.2
*/
Blob getBlob(int columnIndex) throws SQLException;
@Nullable Blob getBlob(int columnIndex) throws SQLException;

/**
* Retrieves the value of the designated column in the current row
Expand Down Expand Up @@ -4115,7 +4115,7 @@ void updateCharacterStream(String columnLabel,
* this method
* @since 1.7
*/
public <T extends @Nullable Object> @Nullable T getObject(int columnIndex, Class<T> type) throws SQLException;
public <T> @Nullable T getObject(int columnIndex, Class<T> type) throws SQLException;


/**
Expand Down Expand Up @@ -4146,7 +4146,7 @@ void updateCharacterStream(String columnLabel,
* this method
* @since 1.7
*/
public <T extends @Nullable Object> @Nullable T getObject(String columnLabel, Class<T> type) throws SQLException;
public <T> @Nullable T getObject(String columnLabel, Class<T> type) throws SQLException;

//------------------------- JDBC 4.2 -----------------------------------

Expand Down