Search This Blog

Java Exceptions Catalog Part 4: Security, Cryptography, Database & Naming Exceptions

Java Exceptions Catalog - Part 4: Security, Cryptography, Database & Naming Exceptions

Java Exceptions Catalog - Part 4: Security, Database & Naming

Comprehensive guide to database errors (java.sql), security and cryptography exceptions (java.security & javax.crypto), and JNDI directory service faults (javax.naming).

1. Relational Database Exceptions (java.sql Package)

JAVA.SQL

java.sql.SQLException

Root exception providing information on database access errors, connection issues, or SQL query failures.

Resolution
Inspect error codes via getErrorCode() and SQL state codes via getSQLState() for driver-specific diagnosis.
JAVA.SQL

java.sql.SQLIntegrityConstraintViolationException

An SQL command violates a database constraint (e.g., duplicate primary key, unique index violation, or foreign key mismatch).

Resolution
Verify entity uniqueness before inserting, or implement upside/merge queries (`ON CONFLICT DO UPDATE`).
JAVA.SQL

java.sql.SQLTimeoutException

The query execution time exceeded the specified timeout limit set on a Statement or PreparedStatement.

Resolution
Optimize SQL query performance, create missing database table indexes, or increase statement timeout limits.
JAVA.SQL

java.sql.SQLSyntaxErrorException

The SQL string sent to the database engine contains invalid syntax or unknown table/column identifiers.

JAVA.SQL

java.sql.BatchUpdateException

An error occurred during a batch update operation (retrievable update counts via getUpdateCounts()).

JAVA.SQL

java.sql.SQLDataException

Data evaluation error during SQL execution (e.g., numeric value out of range or string truncation on insert).

JAVA.SQL

java.sql.SQLFeatureNotSupportedException

The underlying JDBC driver or database engine does not support a specific requested feature.

JAVA.SQL

java.sql.SQLNonTransientConnectionException

A persistent connection failure occurred (e.g., invalid connection credentials or closed socket) that will not succeed upon retry without fixing the root cause.

JAVA.SQL

java.sql.SQLTransientException

A temporary database operation failure (e.g., deadlock or transaction rollback) that may succeed if retried.

2. Security & Cryptography (java.security & javax.crypto Packages)

SECURITY

java.security.NoSuchAlgorithmException

A requested cryptographic algorithm (e.g., `AES`, `SHA-256`, `RSA`) is not available in the current environment or security provider.

Resolution
Check algorithm name spelling or register an external Security Provider (e.g., BouncyCastle).
SECURITY

java.security.InvalidKeyException

Invalid key specified during initialization (e.g., wrong key size, uninitialized key, or key type mismatch for algorithm).

Resolution
Verify key bit-length compatibility and format (e.g., PKCS8 or X509 encoding).
CRYPTO

javax.crypto.BadPaddingException

Decryption padding check failed. Commonly indicates an incorrect secret key was used for decryption or ciphertext was corrupted.

Resolution
Ensure identical keys, initialization vectors (IVs), and cipher padding schemes (`AES/CBC/PKCS5Padding`) are used for both encryption and decryption.
CRYPTO

javax.crypto.IllegalBlockSizeException

The length of data provided to a block cipher does not match the cipher's block size requirement.

CRYPTO

javax.crypto.NoSuchPaddingException

A requested cipher padding mechanism is not supported in the execution environment.

SECURITY

java.security.KeyStoreException

Generic exception covering underlying failures while manipulating a Java `KeyStore` instance.

SECURITY

java.security.UnrecoverableKeyException

A key cannot be recovered from a KeyStore, usually due to an incorrect key password.

SECURITY

java.security.SignatureException

Failures encountered during cryptographic digital signature generation or verification operations.

SECURITY

java.security.cert.CertificateException

Base class for errors during parsing, validation, or verification of X.509 security certificates.

SECURITY

java.security.InvalidAlgorithmParameterException

Invalid or inappropriate initialization parameters (e.g., invalid Initialization Vector size) passed to a cipher.

3. Directory & Naming Services (javax.naming Package)

JNDI

javax.naming.NamingException

Base exception class for errors thrown by JNDI context lookups and LDAP directory operations.

JNDI

javax.naming.NameNotFoundException

Indicates that the specified binding or JNDI name cannot be found in the directory context.

Resolution
Verify JNDI resource mapping names in application server deployment descriptors (`web.xml`, `context.xml`).
JNDI

javax.naming.AuthenticationException

Thrown when credential authentication fails while opening a directory service context (e.g., LDAP connection).

JNDI

javax.naming.CommunicationException

Unable to communicate with the directory server or remote JNDI provider.

JNDI

javax.naming.ServiceUnavailableException

The target naming or directory service provider is unreachable or temporarily unavailable.

JNDI

javax.naming.InvalidNameException

The specified name string violates the naming syntax of the directory service provider.

No comments:

Post a Comment