apache/shardingsphere · error · IllegalStateException

Can not find field name `%s` in class %s.

Error message

Can not find field name `%s` in class %s.

What it means

Thrown by the Firebird frontend when a client attempts to start a new transaction while FirebirdTransactionIdGenerator reports an active transaction for the same connection. The proxy enforces at most MAX_CONCURRENT_TRANSACTIONS (=1 per connection) transactions, mirroring Firebird's single-active-transaction-per-connection model. ExcessTransactionsException signals a protocol misuse rather than a resource exhaustion.

Source

Thrown at agent/plugins/core/src/main/java/org/apache/shardingsphere/agent/plugin/core/util/AgentReflectionUtils.java:47

 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AgentReflectionUtils {
    
    /**
     * Get field value.
     *
     * @param target target
     * @param fieldName field name
     * @param <T> type of field value
     * @return field value
     * @throws IllegalStateException illegal state exception
     */
    public static <T> T getFieldValue(final Object target, final String fieldName) {
        Optional<Field> field = findField(fieldName, target.getClass());
        if (field.isPresent()) {
            return getFieldValue(target, field.get());
        }
        throw new IllegalStateException(String.format("Can not find field name `%s` in class %s.", fieldName, target.getClass()));
    }
    
    @SuppressWarnings("unchecked")
    @SneakyThrows(IllegalAccessException.class)
    private static <T> T getFieldValue(final Object target, final Field field) {
        boolean accessible = field.isAccessible();
        if (!accessible) {
            field.setAccessible(true);
        }
        T result = (T) field.get(target);
        if (!accessible) {
            field.setAccessible(false);
        }
        return result;
    }
    
    private static Optional<Field> findField(final String fieldName, final Class<?> targetClass) {
        Class<?> currentTargetClass = targetClass;

View on GitHub (pinned to e952770a21)

Solutions

  1. Commit or roll back the current transaction (and let the proxy close the handle) before issuing a new start-transaction on the same connection.
  2. Audit error paths in client code to guarantee a terminal commit/rollback is always issued (try/finally).
  3. If the client expects parallel transactions, use a separate connection per transaction — Firebird protocol here allows one per connection.
  4. If the error appears after a prior failure, close and reopen the connection to reset tracked transaction state, then retry.

Example fix

// before
conn.startTransaction();
try {
    doWork();
} catch (Exception e) {
    // forgot rollback; next startTransaction throws
}
conn.startTransaction();

// after
conn.startTransaction();
try {
    doWork();
    conn.commit();
} catch (Exception e) {
    conn.rollback();
} finally {
    conn.endTransaction(); // clears handle
}
Defensive patterns

Strategy: validation

Validate before calling

// Client-side guard before starting a Firebird transaction
if (txHandle >= 0) throw new IllegalStateException("Transaction already active; commit or roll back first");
txHandle = conn.startTransaction();

Prevention

When it happens

Trigger: Sending a Firebird start-transaction packet on a connection where hasActiveTransaction(connectionId) is true: starting a second transaction without committing/rolling back the first, or after a failed commit/rollback path that did not close the tracked transaction.

Common situations: Client code that begins a transaction, hits an error path that skips commit/rollback, then begins another on the same connection; drivers that auto-begin transactions around each statement while an explicit transaction is open; state left over after an abnormal disconnect/reconnect on the same connection id.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/189129315141dcf0. Report an issue: GitHub.