Skip to content

Builder definitions in final Appender implementations unncessarily use Generics on Builder class #3368

@JWT007

Description

@JWT007

Log4j 2.24

Not technically a bug??? But not a feature-request either...just pointing it out...if no interest in changing this from L4J team go ahead and close it

The appender Builders (ConsoleAppender.Builder, FileAppender.Builder, etc) have been generically defiined.

For example:

    /**
     * Builds ConsoleAppender instances.
     * @param <B> The type to build
     */
    public static class Builder<B extends Builder<B>> 
            extends AbstractOutputStreamAppender.Builder<B>
            implements org.apache.logging.log4j.core.util.Builder<ConsoleAppender> {
            ...
    }

This means when not chaining you need to handle the generics:

ConsoleAppender.Builder<?> builder = ConsoleAppender.newBuilder();

This is OK for the abstract Builders that are inherited, but a wee bit non-standard for concrete builder implementations.

Since the appender classes are final one might assume its builders can also be final and don't need the generics on the class itself.

I think it could be simplified::

For example ConsoleAppender:

  public static final class Builder 
      extends AbstractOutputStreamAppender.Builder<Builder> 
      implements org.apache.logging.log4j.core.util.Builder<ConsoleAppender>

ConsoleAppender.Builder builder = ConsoleAppender.newBuilder();

From a coding perspective a trivial change but more of a binary compatibility problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    To triage

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions