Skip to content

jooby: SSIHandler - better exception handling #197

@xsalefter

Description

@xsalefter

Inside the try-with-resources, the code closes in but reads from stream. While they currently reference the same object, this is confusing and easy to break during refactors; read from in to match the managed resource. Also, throwing a bare NoSuchElementException with no message makes debugging missing includes harder—consider including the include path (e.g., pass key into text(...) or throw from file(key) with a message).

    InputStream stream = getClass().getResourceAsStream(file);
    if (stream == null) {
      throw new NoSuchElementException("Resource not found: " + file);
    }
    return text(stream);
  }

  private String text(final InputStream stream) {
    try (InputStream in = stream) {
      return CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8));
    } catch (IOException x) {

Originally posted by @Copilot in #194 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions