Sfoglia il codice sorgente

Fix NullPointerException in logger when message is null (#12588)

LogSection.publish and VConsole.log/VConsole.error methods now replace
null message with an empty string ("")

Change-Id: I735b51bce971ababe2557f1b6c317c01066bc03c
tags/7.1.8
Artem Godin 10 anni fa
parent
commit
503e5757bb

+ 14
- 4
client/src/com/vaadin/client/VConsole.java Vedi File

@@ -41,25 +41,35 @@ public class VConsole {

public static void log(String msg) {
if (LogConfiguration.loggingIsEnabled(Level.INFO)) {
getLogger().log(Level.INFO, msg);
// Check for null, so no NullPointerException is generated when
// formatting (#12588)
getLogger().log(Level.INFO, msg == null ? "null" : msg);
}
}

public static void log(Throwable e) {
if (LogConfiguration.loggingIsEnabled(Level.INFO)) {
getLogger().log(Level.INFO, e.getMessage(), e);
// Check for null, so no NullPointerException is generated when
// formatting (#12588)
getLogger().log(Level.INFO,
e.getMessage() == null ? "" : e.getMessage(), e);
}
}

public static void error(Throwable e) {
if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) {
getLogger().log(Level.SEVERE, e.getMessage(), e);
// Check for null, so no NullPointerException is generated when
// formatting (#12588)
getLogger().log(Level.SEVERE,
e.getMessage() == null ? "" : e.getMessage(), e);
}
}

public static void error(String msg) {
if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) {
getLogger().log(Level.SEVERE, msg);
// Check for null, so no NullPointerException is generated when
// formatting (#12588)
getLogger().log(Level.SEVERE, msg == null ? "null" : msg);
}
}


+ 6
- 0
client/src/com/vaadin/client/debug/internal/LogSection.java Vedi File

@@ -73,6 +73,12 @@ public class LogSection implements Section {
return;
}

// If no message is provided, record.getMessage will be null and so
// the formatter.format will fail with NullPointerException (#12588)
if (record.getMessage() == null) {
record.setMessage("");
}

Formatter formatter = getFormatter();
String msg = formatter.format(record);


Loading…
Annulla
Salva