Skip to content

Commit

Permalink
Annotate java.util.logging.Hander.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk authored May 1, 2023
1 parent 03e55c2 commit c375331
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/java.logging/share/classes/java/util/logging/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.io.UnsupportedEncodingException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A {@code Handler} object takes log messages from a {@code Logger} and
Expand All @@ -53,6 +55,7 @@
*/

@AnnotatedFor({"interning"})
@NullMarked
public abstract @UsesObjectEquals class Handler {
private static final int offValue = Level.OFF.intValue();
private final LogManager manager = LogManager.getLogManager();
Expand Down Expand Up @@ -137,7 +140,7 @@ public Void run() {
* @param record description of the log event. A null record is
* silently ignored and is not published
*/
public abstract void publish(LogRecord record);
public abstract void publish(@Nullable LogRecord record);

/**
* Flush any buffered output.
Expand Down Expand Up @@ -177,7 +180,7 @@ public synchronized void setFormatter(Formatter newFormatter) throws SecurityExc
* Return the {@code Formatter} for this {@code Handler}.
* @return the {@code Formatter} (may be null).
*/
public Formatter getFormatter() {
public @Nullable Formatter getFormatter() {
return formatter;
}

Expand All @@ -194,7 +197,7 @@ public Formatter getFormatter() {
* @exception UnsupportedEncodingException if the named encoding is
* not supported.
*/
public synchronized void setEncoding(String encoding)
public synchronized void setEncoding(@Nullable String encoding)
throws SecurityException, java.io.UnsupportedEncodingException {
checkPermission();
if (encoding != null) {
Expand All @@ -215,7 +218,7 @@ public synchronized void setEncoding(String encoding)
* @return The encoding name. May be null, which indicates the
* default encoding should be used.
*/
public String getEncoding() {
public @Nullable String getEncoding() {
return encoding;
}

Expand All @@ -230,7 +233,7 @@ public String getEncoding() {
* @exception SecurityException if a security manager exists and if
* the caller does not have {@code LoggingPermission("control")}.
*/
public synchronized void setFilter(Filter newFilter) throws SecurityException {
public synchronized void setFilter(@Nullable Filter newFilter) throws SecurityException {
checkPermission();
filter = newFilter;
}
Expand All @@ -240,7 +243,7 @@ public synchronized void setFilter(Filter newFilter) throws SecurityException {
*
* @return a {@code Filter} object (may be null)
*/
public Filter getFilter() {
public @Nullable Filter getFilter() {
return filter;
}

Expand Down Expand Up @@ -284,7 +287,7 @@ public ErrorManager getErrorManager() {
* @param ex an exception (may be null)
* @param code an error code defined in ErrorManager
*/
protected void reportError(String msg, Exception ex, int code) {
protected void reportError(@Nullable String msg, @Nullable Exception ex, int code) {
try {
errorManager.error(msg, ex, code);
} catch (Exception ex2) {
Expand Down Expand Up @@ -337,7 +340,8 @@ public Level getLevel() {
* @return true if the {@code LogRecord} would be logged.
*
*/
public boolean isLoggable(LogRecord record) {
// JDK11 has a bug which makes null records cause NPE, despite the spec. Later versions fix it.
public boolean isLoggable(@Nullable LogRecord record) {
final int levelValue = getLevel().intValue();
if (record.getLevel().intValue() < levelValue || levelValue == offValue) {
return false;
Expand Down

0 comments on commit c375331

Please sign in to comment.