Parcourir la source

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 il y a 10 ans
Parent
révision
503e5757bb

+ 14
- 4
client/src/com/vaadin/client/VConsole.java Voir le fichier



public static void log(String msg) { public static void log(String msg) {
if (LogConfiguration.loggingIsEnabled(Level.INFO)) { 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) { public static void log(Throwable e) {
if (LogConfiguration.loggingIsEnabled(Level.INFO)) { 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) { public static void error(Throwable e) {
if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) { 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) { public static void error(String msg) {
if (LogConfiguration.loggingIsEnabled(Level.SEVERE)) { 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 Voir le fichier

return; 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(); Formatter formatter = getFormatter();
String msg = formatter.format(record); String msg = formatter.format(record);



Chargement…
Annuler
Enregistrer