OpenFeign/feign · error · IllegalStateException

Could not add file handler.

Error message

Could not add file handler.

What it means

Logged/raised by Logger.JavaLogger.appendToFile when constructing a java.util.logging FileHandler for the given logfile path fails — the path is unwritable, its directory does not exist, or the file is locked by another process. It is a configuration guard for log setup: the input at fault is the logfile path string passed to appendToFile, not the HTTP traffic being logged.

Solutions

  1. Ensure the log file's parent directory exists and the process has write permissions on it
  2. Use an absolute path or one relative to the working directory that is valid at runtime
  3. Close or avoid sharing the same log file with another concurrently running process (FileHandler locks its target)
  4. If file logging is unavailable, fall back to Logger.Level and console/jdk logging via the default JavaLogger constructor
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at core/src/main/java/feign/Logger.java:266 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/d70c22a068cf9586. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/feign/Logger.java:266

    /**
     * Helper that configures java.util.logging to sanely log messages at FINE level without
     * additional formatting.
     */
    public JavaLogger appendToFile(String logfile) {
      logger.setLevel(java.util.logging.Level.FINE);
      try {
        FileHandler handler = new FileHandler(logfile, true);
        handler.setFormatter(
            new SimpleFormatter() {
              @Override
              public String format(LogRecord record) {
                return String.format("%s%n", record.getMessage()); // NOPMD
              }
            });
        logger.addHandler(handler);
        handlers.add(handler);
      } catch (IOException e) {
        throw new IllegalStateException("Could not add file handler.", e);
      }
      return this;
    }

    @Override
    public void close() {
      for (Handler handler : handlers) {
        logger.removeHandler(handler);
        handler.close();
      }
      handlers.clear();
    }
  }

  public static class NoOpLogger extends Logger {

    @Override
    protected void logRequest(String configKey, Level logLevel, Request request) {}

View on GitHub (pinned to e2a1e27560)