summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorJake Wharton <jakew@google.com>2018-06-04 19:22:14 -0400
committerJake Wharton <jakew@google.com>2018-06-04 21:33:52 -0400
commitd4a238971d3c656a3eb571de2b8728f5bac8c012 (patch)
tree4a4b40513d9b1f22fb3d32ecec5aa694bad0d8f1 /core/java
parent232e558006179c3792e681232c63163cc54ac13f (diff)
Annotate Log reference parameters and return types.
Bug: 78245676 Test: atest LogNullabilityTest Change-Id: Icbb26d23ed89e1fabd019108d4484902468c165e
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/util/Log.java54
1 files changed, 29 insertions, 25 deletions
diff --git a/core/java/android/util/Log.java b/core/java/android/util/Log.java
index 029986534890..dccbf14a254d 100644
--- a/core/java/android/util/Log.java
+++ b/core/java/android/util/Log.java
@@ -16,6 +16,8 @@
package android.util;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.os.DeadSystemException;
import com.android.internal.os.RuntimeInit;
@@ -120,7 +122,7 @@ public final class Log {
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
- public static int v(String tag, String msg) {
+ public static int v(@Nullable String tag, @NonNull String msg) {
return println_native(LOG_ID_MAIN, VERBOSE, tag, msg);
}
@@ -131,7 +133,7 @@ public final class Log {
* @param msg The message you would like logged.
* @param tr An exception to log
*/
- public static int v(String tag, String msg, Throwable tr) {
+ public static int v(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
return printlns(LOG_ID_MAIN, VERBOSE, tag, msg, tr);
}
@@ -141,7 +143,7 @@ public final class Log {
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
- public static int d(String tag, String msg) {
+ public static int d(@Nullable String tag, @NonNull String msg) {
return println_native(LOG_ID_MAIN, DEBUG, tag, msg);
}
@@ -152,7 +154,7 @@ public final class Log {
* @param msg The message you would like logged.
* @param tr An exception to log
*/
- public static int d(String tag, String msg, Throwable tr) {
+ public static int d(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
return printlns(LOG_ID_MAIN, DEBUG, tag, msg, tr);
}
@@ -162,7 +164,7 @@ public final class Log {
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
- public static int i(String tag, String msg) {
+ public static int i(@Nullable String tag, @NonNull String msg) {
return println_native(LOG_ID_MAIN, INFO, tag, msg);
}
@@ -173,7 +175,7 @@ public final class Log {
* @param msg The message you would like logged.
* @param tr An exception to log
*/
- public static int i(String tag, String msg, Throwable tr) {
+ public static int i(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
return printlns(LOG_ID_MAIN, INFO, tag, msg, tr);
}
@@ -183,7 +185,7 @@ public final class Log {
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
- public static int w(String tag, String msg) {
+ public static int w(@Nullable String tag, @NonNull String msg) {
return println_native(LOG_ID_MAIN, WARN, tag, msg);
}
@@ -194,7 +196,7 @@ public final class Log {
* @param msg The message you would like logged.
* @param tr An exception to log
*/
- public static int w(String tag, String msg, Throwable tr) {
+ public static int w(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
return printlns(LOG_ID_MAIN, WARN, tag, msg, tr);
}
@@ -218,15 +220,15 @@ public final class Log {
* for Nougat (7.0) releases (API <= 23) and prior, there is no
* tag limit of concern after this API level.
*/
- public static native boolean isLoggable(String tag, int level);
+ public static native boolean isLoggable(@Nullable String tag, int level);
- /*
+ /**
* Send a {@link #WARN} log message and log the exception.
* @param tag Used to identify the source of a log message. It usually identifies
* the class or activity where the log call occurs.
* @param tr An exception to log
*/
- public static int w(String tag, Throwable tr) {
+ public static int w(@Nullable String tag, @Nullable Throwable tr) {
return printlns(LOG_ID_MAIN, WARN, tag, "", tr);
}
@@ -236,7 +238,7 @@ public final class Log {
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
- public static int e(String tag, String msg) {
+ public static int e(@Nullable String tag, @NonNull String msg) {
return println_native(LOG_ID_MAIN, ERROR, tag, msg);
}
@@ -247,7 +249,7 @@ public final class Log {
* @param msg The message you would like logged.
* @param tr An exception to log
*/
- public static int e(String tag, String msg, Throwable tr) {
+ public static int e(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
return printlns(LOG_ID_MAIN, ERROR, tag, msg, tr);
}
@@ -260,7 +262,7 @@ public final class Log {
* @param tag Used to identify the source of a log message.
* @param msg The message you would like logged.
*/
- public static int wtf(String tag, String msg) {
+ public static int wtf(@Nullable String tag, @Nullable String msg) {
return wtf(LOG_ID_MAIN, tag, msg, null, false, false);
}
@@ -269,7 +271,7 @@ public final class Log {
* call stack.
* @hide
*/
- public static int wtfStack(String tag, String msg) {
+ public static int wtfStack(@Nullable String tag, @Nullable String msg) {
return wtf(LOG_ID_MAIN, tag, msg, null, true, false);
}
@@ -279,7 +281,7 @@ public final class Log {
* @param tag Used to identify the source of a log message.
* @param tr An exception to log.
*/
- public static int wtf(String tag, Throwable tr) {
+ public static int wtf(@Nullable String tag, @NonNull Throwable tr) {
return wtf(LOG_ID_MAIN, tag, tr.getMessage(), tr, false, false);
}
@@ -290,12 +292,12 @@ public final class Log {
* @param msg The message you would like logged.
* @param tr An exception to log. May be null.
*/
- public static int wtf(String tag, String msg, Throwable tr) {
+ public static int wtf(@Nullable String tag, @Nullable String msg, @Nullable Throwable tr) {
return wtf(LOG_ID_MAIN, tag, msg, tr, false, false);
}
- static int wtf(int logId, String tag, String msg, Throwable tr, boolean localStack,
- boolean system) {
+ static int wtf(int logId, @Nullable String tag, @Nullable String msg, @Nullable Throwable tr,
+ boolean localStack, boolean system) {
TerribleFailure what = new TerribleFailure(msg, tr);
// Only mark this as ERROR, do not use ASSERT since that should be
// reserved for cases where the system is guaranteed to abort.
@@ -305,7 +307,7 @@ public final class Log {
return bytes;
}
- static void wtfQuiet(int logId, String tag, String msg, boolean system) {
+ static void wtfQuiet(int logId, @Nullable String tag, @Nullable String msg, boolean system) {
TerribleFailure what = new TerribleFailure(msg, null);
sWtfHandler.onTerribleFailure(tag, what, system);
}
@@ -317,7 +319,8 @@ public final class Log {
*
* @hide
*/
- public static TerribleFailureHandler setWtfHandler(TerribleFailureHandler handler) {
+ @NonNull
+ public static TerribleFailureHandler setWtfHandler(@NonNull TerribleFailureHandler handler) {
if (handler == null) {
throw new NullPointerException("handler == null");
}
@@ -330,7 +333,8 @@ public final class Log {
* Handy function to get a loggable stack trace from a Throwable
* @param tr An exception to log
*/
- public static String getStackTraceString(Throwable tr) {
+ @NonNull
+ public static String getStackTraceString(@Nullable Throwable tr) {
if (tr == null) {
return "";
}
@@ -360,7 +364,7 @@ public final class Log {
* @param msg The message you would like logged.
* @return The number of bytes written.
*/
- public static int println(int priority, String tag, String msg) {
+ public static int println(int priority, @Nullable String tag, @NonNull String msg) {
return println_native(LOG_ID_MAIN, priority, tag, msg);
}
@@ -385,8 +389,8 @@ public final class Log {
* chunks. This is to avoid truncation.
* @hide
*/
- public static int printlns(int bufID, int priority, String tag, String msg,
- Throwable tr) {
+ public static int printlns(int bufID, int priority, @Nullable String tag, @NonNull String msg,
+ @Nullable Throwable tr) {
ImmediateLogWriter logWriter = new ImmediateLogWriter(bufID, priority, tag);
// Acceptable buffer size. Get the native buffer size, subtract two zero terminators,
// and the length of the tag.