Added in API level 28

Violation


public abstract class Violation
extends Throwable

java.lang.Object
   ↳ java.lang.Throwable
     ↳ android.os.strictmode.Violation


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

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.