Added in API level 28

Violation


public abstract class Violation
extends Throwable

java.lang.Object
   ↳ java.lang.Throwable
     ↳ android.os.strictmode.Violation
CleartextNetworkViolation  
ContentUriWithoutPermissionViolation  
CredentialProtectedWhileLockedViolation Subclass of Violation that is used when a process accesses filesystem paths stored in credential protected storage areas while the user is locked. 
CustomViolation  
DiskReadViolation  
DiskWriteViolation  
ExplicitGcViolation See #StrictMode.ThreadPolicy.Builder.detectExplicitGc()
FileUriExposedViolation  
ImplicitDirectBootViolation Subclass of Violation that is used when a process implicitly relies on automatic Direct Boot filtering. 
IncorrectContextUseViolation Incorrect usage of Context, such as obtaining a UI service from non-UI Context instance. 
InstanceCountViolation  
IntentReceiverLeakedViolation  
LeakedClosableViolation  
NetworkViolation  
NonSdkApiUsedViolation Subclass of Violation that is used when a process accesses a non SDK API. 
ResourceMismatchViolation  
ServiceConnectionLeakedViolation  
SqliteObjectLeakedViolation  
UnbufferedIoViolation See #Builder.detectUnbufferedIo() 
UnsafeIntentLaunchViolation Violation raised when your app launches an Intent which originated from outside your app. 
UntaggedSocketViolation  
WebViewMethodCalledOnWrongThreadViolation  


Root class for all StrictMode violations.

Summary

Public methods

Throwable fillInStackTrace()

Fills in the execution stack trace.

int hashCode()

Returns a hash code value for the object.

Throwable initCause(Throwable cause)

Initializes the cause of this throwable to the specified value.

void setStackTrace(StackTraceElement[] stackTrace)

Sets the stack trace elements that will be returned by getStackTrace() and printed by printStackTrace() and related methods.

Inherited methods

final void addSuppressed(Throwable exception)

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Throwable fillInStackTrace()

Fills in the execution stack trace.

Throwable getCause()

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

String getLocalizedMessage()

Creates a localized description of this throwable.

String getMessage()

Returns the detail message string of this throwable.

StackTraceElement[] getStackTrace()

Provides programmatic access to the stack trace information printed by printStackTrace().

final Throwable[] getSuppressed()

Returns an array containing all of the exceptions that were suppressed, typically by the try-with-resources statement, in order to deliver this exception.

Throwable initCause(Throwable cause)

Initializes the cause of this throwable to the specified value.

void printStackTrace()

Prints this throwable and its backtrace to the standard error stream.

void printStackTrace(PrintWriter s)

Prints this throwable and its backtrace to the specified print writer.

void printStackTrace(PrintStream s)

Prints this throwable and its backtrace to the specified print stream.

void setStackTrace(StackTraceElement[] stackTrace)

Sets the stack trace elements that will be returned by getStackTrace() and printed by printStackTrace() and related methods.

String toString()

Returns a short description of this throwable.

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public methods

fillInStackTrace

Added in API level 28
public Throwable fillInStackTrace ()

Fills in the execution stack trace. This method records within this Throwable object information about the current state of the stack frames for the current thread.

If the stack trace of this Throwable writable, calling this method has no effect.

Returns
Throwable a reference to this Throwable instance.

hashCode

Added in API level 28
public int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

Returns
int a hash code value for this object.

initCause

Added in API level 28
public Throwable initCause (Throwable cause)

Initializes the cause of this throwable to the specified value. (The cause is the throwable that caused this throwable to get thrown.)

This method can be called at most once. It is generally called from within the constructor, or immediately after creating the throwable. If this throwable was created with Throwable(java.lang.Throwable) or Throwable(java.lang.String, java.lang.Throwable), this method cannot be called even once.

An example of using this method on a legacy throwable type without other support for setting the cause is:

 try {
     lowLevelOp();
 } catch (LowLevelException le) {
     throw (HighLevelException)
           new HighLevelException().initCause(le); // Legacy constructor
 }
 

Parameters
cause Throwable: the cause (which is saved for later retrieval by the Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)

Returns
Throwable a reference to this Throwable instance.

setStackTrace

Added in API level 28
public void setStackTrace (StackTraceElement[] stackTrace)

Sets the stack trace elements that will be returned by getStackTrace() and printed by printStackTrace() and related methods. This method, which is designed for use by RPC frameworks and other advanced systems, allows the client to override the default stack trace that is either generated by fillInStackTrace() when a throwable is constructed or deserialized when a throwable is read from a serialization stream.

If the stack trace of this Throwable writable, calling this method has no effect other than validating its argument.

Parameters
stackTrace StackTraceElement: the stack trace elements to be associated with this Throwable. The specified array is copied by this call; changes in the specified array after the method invocation returns will have no affect on this Throwable's stack trace.