Skip to content

DeviceAlreadyConnectedException

opencode-agent[bot] edited this page May 11, 2026 · 1 revision

DeviceAlreadyConnectedException

Exception thrown when attempting to connect a device that is already bound to a driver.

Overview

DeviceAlreadyConnectedException is a minor driver error exception (value 2) thrown within JNode's device framework when an attempt is made to connect a Driver to a Device that already has an active driver association. It extends DriverException, which itself extends Exception.

The exception enforces the one-driver-per-device invariant in JNode's device lifecycle management.

Key Components

Class Location Purpose
DeviceAlreadyConnectedException core/src/driver/org/jnode/driver/DeviceAlreadyConnectedException.java The exception class
DriverException core/src/driver/org/jnode/driver/DriverException.java Parent exception class
Driver core/src/driver/org/jnode/driver/Driver.java Driver base class with connect() method
Device core/src/driver/org/jnode/driver/Device.java Device base class with setDriver() method

How It Works

Exception Hierarchy

Exception
└── DriverException
    └── DeviceAlreadyConnectedException

Triggering Conditions

The exception is thrown by Driver.connect(Device) at line 73-76 in Driver.java:

protected final void connect(Device device) throws DriverException {
    if (this.device != null) {
        throw new DriverException("This driver is already connected to a device");
    }
    verifyConnect(device);
    this.device = device;
    afterConnect(device);
}

The exception can be thrown when:

  1. A Driver instance that is already bound to one Device receives a call to connect() with a different Device
  2. A Device.setDriver() call propagates to driver.connect() where the driver is already connected

Connection Flow

Device.setDriver(driver)
    └── driver.connect(this)  // Throws if driver already has a device
        └── Driver.connect(device) checks this.device != null

Constructor Variants

The exception provides four constructors for flexibility:

  • DeviceAlreadyConnectedException() — No-arg
  • DeviceAlreadyConnectedException(String s) — Message only
  • DeviceAlreadyConnectedException(Throwable cause) — Cause only
  • DeviceAlreadyConnectedException(String message, Throwable cause) — Both

Gotchas

  • Not directly thrown: The exception is not thrown directly; instead Driver.connect() throws a DriverException with this as the cause or as the exception type itself
  • Single-device constraint: Drivers in JNode are single-device — once a driver is connected to a device, it cannot be rebound to another device
  • Silent failure prevention: The exception enforces the one-driver-per-device invariant that prevents undefined system state

Related Pages

  • Driver-Framework — Parent framework containing device and driver lifecycle management
  • DeviceManager — Central registry managing device-driver bindings
  • DeviceAPI — Interface pattern for device functionality exposure
  • DriverException — Parent exception class for all driver-related errors

Clone this wiki locally