Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/java/security/cert/CertPath#nestedclasses) \| [Protected Ctors](https://developer.android.com/reference/java/security/cert/CertPath#proctors) \| [Methods](https://developer.android.com/reference/java/security/cert/CertPath#pubmethods) \| [Protected Methods](https://developer.android.com/reference/java/security/cert/CertPath#promethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/cert/CertPath#inhmethods)

# CertPath

` public abstract class CertPath `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/io/Serializable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.security.cert.CertPath |

<br />

*** ** * ** ***

An immutable sequence of certificates (a certification path).

This is an abstract class that defines the methods common to all `CertPath`s. Subclasses can handle different kinds of certificates (X.509, PGP, etc.).

All `CertPath` objects have a type, a list of `Certificate`s, and one or more supported encodings. Because the `CertPath` class is immutable, a `CertPath` cannot change in any externally visible way after being constructed. This stipulation applies to all public fields and methods of this class and any added or overridden by subclasses.

The type is a `String` that identifies the type of `Certificate`s in the certification path. For each certificate `cert` in a certification path `certPath`, `cert.getType().equals(certPath.getType())` must be `true`.

The list of `Certificate`s is an ordered `List` of zero or more `Certificate`s. This `List` and all of the `Certificate`s contained in it must be immutable.

Each `CertPath` object must support one or more encodings so that the object can be translated into a byte array for storage or transmission to other parties. Preferably, these encodings should be well-documented standards (such as PKCS#7). One of the encodings supported by a `CertPath` is considered the default encoding. This encoding is used if no encoding is explicitly requested (for the `https://developer.android.com/reference/java/security/cert/CertPath#getEncoded()` method, for instance).

All `CertPath` objects are also `Serializable`. `CertPath` objects are resolved into an alternate `https://developer.android.com/reference/java/security/cert/CertPath.CertPathRep` object during serialization. This allows a `CertPath` object to be serialized into an equivalent representation regardless of its underlying implementation.

`CertPath` objects can be created with a `CertificateFactory` or they can be returned by other classes, such as a `CertPathBuilder`.

By convention, X.509 `CertPath`s (consisting of `X509Certificate`s), are ordered starting with the target certificate and ending with a certificate issued by the trust anchor. That is, the issuer of one certificate is the subject of the following one. The certificate representing the `https://developer.android.com/reference/java/security/cert/TrustAnchor` should not be included in the certification path. Unvalidated X.509 `CertPath`s may not follow these conventions. PKIX `CertPathValidator`s will detect any departure from these conventions that cause the certification path to be invalid and throw a `CertPathValidatorException`.

Every implementation of the Java platform is required to support the following standard `CertPath` encodings:

- `PKCS7`
- `PkiPath`

These encodings are described in the [CertPath Encodings section](https://docs.oracle.com/en/java/javase/17/docs/specs/security/standard-names.html#certpath-encodings) of the Java Security Standard Algorithm Names Specification. Consult the release documentation for your implementation to see if any other encodings are supported.

**Concurrent Access**

All `CertPath` objects must be thread-safe. That is, multiple threads may concurrently invoke the methods defined in this class on a single `CertPath` object (or more than one) with no ill effects. This is also true for the `List` returned by `CertPath.getCertificates`.

Requiring `CertPath` objects to be immutable and thread-safe allows them to be passed around to various pieces of code without worrying about coordinating access. Providing this thread-safety is generally not difficult, since the `CertPath` and `List` objects in question are immutable.
**See also:**

- `https://developer.android.com/reference/java/security/cert/CertificateFactory`
- `https://developer.android.com/reference/java/security/cert/CertPathBuilder`

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/java/security/cert/CertPath.CertPathRep` Alternate `CertPath` class for serialization. |

| ### Protected constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/cert/CertPath#CertPath(java.lang.String)(https://developer.android.com/reference/java/lang/String type) ` Creates a `CertPath` of the specified type. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/java/security/cert/CertPath#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object other) ` Compares this certification path for equality with the specified object. |
| ` abstract https://developer.android.com/reference/java/util/List<? extends https://developer.android.com/reference/java/security/cert/Certificate>` | ` https://developer.android.com/reference/java/security/cert/CertPath#getCertificates()() ` Returns the list of certificates in this certification path. |
| ` abstract byte[]` | ` https://developer.android.com/reference/java/security/cert/CertPath#getEncoded(java.lang.String)(https://developer.android.com/reference/java/lang/String encoding) ` Returns the encoded form of this certification path, using the specified encoding. |
| ` abstract byte[]` | ` https://developer.android.com/reference/java/security/cert/CertPath#getEncoded()() ` Returns the encoded form of this certification path, using the default encoding. |
| ` abstract https://developer.android.com/reference/java/util/Iterator<https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/java/security/cert/CertPath#getEncodings()() ` Returns an iteration of the encodings supported by this certification path, with the default encoding first. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/security/cert/CertPath#getType()() ` Returns the type of `Certificate`s in this certification path. |
| ` int` | ` https://developer.android.com/reference/java/security/cert/CertPath#hashCode()() ` Returns the hashcode for this certification path. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/security/cert/CertPath#toString()() ` Returns a string representation of this certification path. |

| ### Protected methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/security/cert/CertPath#writeReplace()() ` Replaces the `CertPath` to be serialized with a `CertPathRep` object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(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` ` https://developer.android.com/reference/java/lang/Object#wait(long)(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` ` https://developer.android.com/reference/java/lang/Object#wait()() `

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

## Protected constructors

### CertPath

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected CertPath (String type)
```

Creates a `CertPath` of the specified type.

This constructor is protected because most users should use a `CertificateFactory` to create `CertPath`s.

<br />

| Parameters ||
|---|---|
| `type` | `String`: the standard name of the type of `Certificate`s in this path <br /> |

## Public methods

### equals

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object other)
```

Compares this certification path for equality with the specified object. Two `CertPath`s are equal if and only if their types are equal and their certificate `List`s (and by implication the `Certificate`s in those `List`s) are equal. A `CertPath` is never equal to an object that is not a `CertPath`.

This algorithm is implemented by this method. If it is overridden, the behavior specified here must be maintained.

<br />

| Parameters ||
|---|---|
| `other` | `Object`: the object to test for equality with this certification path <br /> |

| Returns ||
|---|---|
| `boolean` | true if the specified object is equal to this certification path, false otherwise <br /> |

### getCertificates

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract List<? extends Certificate> getCertificates ()
```

Returns the list of certificates in this certification path. The `List` returned must be immutable and thread-safe.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<? extends https://developer.android.com/reference/java/security/cert/Certificate>` | an immutable `List` of `Certificate`s (may be empty, but not null) <br /> |

### getEncoded

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract byte[] getEncoded (String encoding)
```

Returns the encoded form of this certification path, using the specified encoding.

<br />

| Parameters ||
|---|---|
| `encoding` | `String`: the name of the encoding to use <br /> |

| Returns ||
|---|---|
| `byte[]` | the encoded bytes <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/security/cert/CertificateEncodingException` | if an encoding error occurs or the encoding requested is not supported |

### getEncoded

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract byte[] getEncoded ()
```

Returns the encoded form of this certification path, using the default encoding.

<br />

| Returns ||
|---|---|
| `byte[]` | the encoded bytes <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/security/cert/CertificateEncodingException` | if an encoding error occurs |

### getEncodings

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract Iterator<String> getEncodings ()
```

Returns an iteration of the encodings supported by this certification path, with the default encoding first. Attempts to modify the returned `Iterator` via its `remove` method result in an `UnsupportedOperationException`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Iterator<https://developer.android.com/reference/java/lang/String>` | an `Iterator` over the names of the supported encodings (as Strings) <br /> |

### getType

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getType ()
```

Returns the type of `Certificate`s in this certification path. This is the same string that would be returned by `https://developer.android.com/reference/java/security/cert/Certificate#getType()` for all `Certificate`s in the certification path.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the type of `Certificate`s in this certification path (never null) <br /> |

### hashCode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns the hashcode for this certification path. The hash code of a certification path is defined to be the result of the following calculation:

    hashCode = path.getType().hashCode();
     hashCode = 31*hashCode + path.getCertificates().hashCode();

This ensures that `path1.equals(path2)` implies that `path1.hashCode()==path2.hashCode()` for any two certification paths, `path1` and `path2`, as required by the general contract of `Object.hashCode`.

<br />

<br />

| Returns ||
|---|---|
| `int` | the hashcode value for this certification path <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of this certification path. This calls the `toString` method on each of the `Certificate`s in the path.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of this certification path <br /> |

## Protected methods

### writeReplace

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Object writeReplace ()
```

Replaces the `CertPath` to be serialized with a `CertPathRep` object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | the `CertPathRep` to be serialized <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/ObjectStreamException` | if a `CertPathRep` object representing this certification path could not be created |