Skip to content

Commit c375331

Browse files
authored
Annotate java.util.logging.Hander.
(eisop#9)
1 parent 03e55c2 commit c375331

File tree

1 file changed

+12
-8
lines changed
  • src/java.logging/share/classes/java/util/logging

1 file changed

+12
-8
lines changed

src/java.logging/share/classes/java/util/logging/Handler.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.io.UnsupportedEncodingException;
3434
import java.security.AccessController;
3535
import java.security.PrivilegedAction;
36+
import org.jspecify.annotations.NullMarked;
37+
import org.jspecify.annotations.Nullable;
3638

3739
/**
3840
* A {@code Handler} object takes log messages from a {@code Logger} and
@@ -53,6 +55,7 @@
5355
*/
5456

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

142145
/**
143146
* Flush any buffered output.
@@ -177,7 +180,7 @@ public synchronized void setFormatter(Formatter newFormatter) throws SecurityExc
177180
* Return the {@code Formatter} for this {@code Handler}.
178181
* @return the {@code Formatter} (may be null).
179182
*/
180-
public Formatter getFormatter() {
183+
public @Nullable Formatter getFormatter() {
181184
return formatter;
182185
}
183186

@@ -194,7 +197,7 @@ public Formatter getFormatter() {
194197
* @exception UnsupportedEncodingException if the named encoding is
195198
* not supported.
196199
*/
197-
public synchronized void setEncoding(String encoding)
200+
public synchronized void setEncoding(@Nullable String encoding)
198201
throws SecurityException, java.io.UnsupportedEncodingException {
199202
checkPermission();
200203
if (encoding != null) {
@@ -215,7 +218,7 @@ public synchronized void setEncoding(String encoding)
215218
* @return The encoding name. May be null, which indicates the
216219
* default encoding should be used.
217220
*/
218-
public String getEncoding() {
221+
public @Nullable String getEncoding() {
219222
return encoding;
220223
}
221224

@@ -230,7 +233,7 @@ public String getEncoding() {
230233
* @exception SecurityException if a security manager exists and if
231234
* the caller does not have {@code LoggingPermission("control")}.
232235
*/
233-
public synchronized void setFilter(Filter newFilter) throws SecurityException {
236+
public synchronized void setFilter(@Nullable Filter newFilter) throws SecurityException {
234237
checkPermission();
235238
filter = newFilter;
236239
}
@@ -240,7 +243,7 @@ public synchronized void setFilter(Filter newFilter) throws SecurityException {
240243
*
241244
* @return a {@code Filter} object (may be null)
242245
*/
243-
public Filter getFilter() {
246+
public @Nullable Filter getFilter() {
244247
return filter;
245248
}
246249

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

0 commit comments

Comments
 (0)