kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject [kafka] branch trunk updated: MINOR: Use method references instead of anonymus classes in Errors (#5525)
Date Thu, 23 Aug 2018 08:44:15 GMT
This is an automated email from the ASF dual-hosted git repository.

ijuma pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 4b2af9d  MINOR: Use method references instead of anonymus classes in Errors (#5525)
4b2af9d is described below

commit 4b2af9de6b3330bc7d9098ff690d80ef64628a6c
Author: Viktor Somogyi <viktorsomogyi@gmail.com>
AuthorDate: Thu Aug 23 10:44:04 2018 +0200

    MINOR: Use method references instead of anonymus classes in Errors (#5525)
    
    Remove `ApiExceptionBuilder` in favour of `Function<String, ApiException>`.
    
    Reviewers: Ismael Juma <ismael@juma.me.uk>
---
 .../org/apache/kafka/common/protocol/Errors.java   | 551 ++++-----------------
 1 file changed, 95 insertions(+), 456 deletions(-)

diff --git a/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java b/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
index 9c522df..090dca3 100644
--- a/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
+++ b/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
@@ -96,6 +96,7 @@ import org.slf4j.LoggerFactory;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.function.Function;
 
 /**
  * This class contains all the client-server errors--those errors that must be sent from
the server to the client. These
@@ -110,533 +111,171 @@ import java.util.Map;
  */
 public enum Errors {
     UNKNOWN_SERVER_ERROR(-1, "The server experienced an unexpected error when processing
the request",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new UnknownServerException(message);
-            }
-        }),
-    NONE(0, null,
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return null;
-            }
-        }),
+            UnknownServerException::new),
+    NONE(0, null, message -> null),
     OFFSET_OUT_OF_RANGE(1, "The requested offset is not within the range of offsets maintained
by the server.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new OffsetOutOfRangeException(message);
-            }
-        }),
+            OffsetOutOfRangeException::new),
     CORRUPT_MESSAGE(2, "This message has failed its CRC checksum, exceeds the valid size,
or is otherwise corrupt.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new CorruptRecordException(message);
-            }
-        }),
+            CorruptRecordException::new),
     UNKNOWN_TOPIC_OR_PARTITION(3, "This server does not host this topic-partition.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new UnknownTopicOrPartitionException(message);
-            }
-        }),
+            UnknownTopicOrPartitionException::new),
     INVALID_FETCH_SIZE(4, "The requested fetch size is invalid.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidFetchSizeException(message);
-            }
-        }),
+            InvalidFetchSizeException::new),
     LEADER_NOT_AVAILABLE(5, "There is no leader for this topic-partition as we are in the
middle of a leadership election.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new LeaderNotAvailableException(message);
-            }
-        }),
+            LeaderNotAvailableException::new),
     NOT_LEADER_FOR_PARTITION(6, "This server is not the leader for that topic-partition.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new NotLeaderForPartitionException(message);
-            }
-        }),
+            NotLeaderForPartitionException::new),
     REQUEST_TIMED_OUT(7, "The request timed out.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new TimeoutException(message);
-            }
-        }),
+            TimeoutException::new),
     BROKER_NOT_AVAILABLE(8, "The broker is not available.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new BrokerNotAvailableException(message);
-            }
-        }),
+            BrokerNotAvailableException::new),
     REPLICA_NOT_AVAILABLE(9, "The replica is not available for the requested topic-partition",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new ReplicaNotAvailableException(message);
-            }
-        }),
+            ReplicaNotAvailableException::new),
     MESSAGE_TOO_LARGE(10, "The request included a message larger than the max message size
the server will accept.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new RecordTooLargeException(message);
-            }
-        }),
+            RecordTooLargeException::new),
     STALE_CONTROLLER_EPOCH(11, "The controller moved to another broker.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new ControllerMovedException(message);
-            }
-        }),
+            ControllerMovedException::new),
     OFFSET_METADATA_TOO_LARGE(12, "The metadata field of the offset request was too large.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new OffsetMetadataTooLarge(message);
-            }
-        }),
+            OffsetMetadataTooLarge::new),
     NETWORK_EXCEPTION(13, "The server disconnected before a response was received.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new NetworkException(message);
-            }
-        }),
+            NetworkException::new),
     COORDINATOR_LOAD_IN_PROGRESS(14, "The coordinator is loading and hence can't process
requests.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new CoordinatorLoadInProgressException(message);
-            }
-        }),
+            CoordinatorLoadInProgressException::new),
     COORDINATOR_NOT_AVAILABLE(15, "The coordinator is not available.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new CoordinatorNotAvailableException(message);
-            }
-        }),
+            CoordinatorNotAvailableException::new),
     NOT_COORDINATOR(16, "This is not the correct coordinator.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new NotCoordinatorException(message);
-            }
-        }),
+            NotCoordinatorException::new),
     INVALID_TOPIC_EXCEPTION(17, "The request attempted to perform an operation on an invalid
topic.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidTopicException(message);
-            }
-        }),
+            InvalidTopicException::new),
     RECORD_LIST_TOO_LARGE(18, "The request included message batch larger than the configured
segment size on the server.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new RecordBatchTooLargeException(message);
-            }
-        }),
+            RecordBatchTooLargeException::new),
     NOT_ENOUGH_REPLICAS(19, "Messages are rejected since there are fewer in-sync replicas
than required.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new NotEnoughReplicasException(message);
-            }
-        }),
+            NotEnoughReplicasException::new),
     NOT_ENOUGH_REPLICAS_AFTER_APPEND(20, "Messages are written to the log, but to fewer in-sync
replicas than required.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new NotEnoughReplicasAfterAppendException(message);
-            }
-        }),
+            NotEnoughReplicasAfterAppendException::new),
     INVALID_REQUIRED_ACKS(21, "Produce request specified an invalid value for required acks.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidRequiredAcksException(message);
-            }
-        }),
+            InvalidRequiredAcksException::new),
     ILLEGAL_GENERATION(22, "Specified group generation id is not valid.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new IllegalGenerationException(message);
-            }
-        }),
+            IllegalGenerationException::new),
     INCONSISTENT_GROUP_PROTOCOL(23,
             "The group member's supported protocols are incompatible with those of existing
members" +
                 " or first group member tried to join with empty protocol type or empty protocol
list.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InconsistentGroupProtocolException(message);
-            }
-        }),
+            InconsistentGroupProtocolException::new),
     INVALID_GROUP_ID(24, "The configured groupId is invalid",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidGroupIdException(message);
-            }
-        }),
+            InvalidGroupIdException::new),
     UNKNOWN_MEMBER_ID(25, "The coordinator is not aware of this member.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new UnknownMemberIdException(message);
-            }
-        }),
+            UnknownMemberIdException::new),
     INVALID_SESSION_TIMEOUT(26,
             "The session timeout is not within the range allowed by the broker " +
             "(as configured by group.min.session.timeout.ms and group.max.session.timeout.ms).",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidSessionTimeoutException(message);
-            }
-        }),
+            InvalidSessionTimeoutException::new),
     REBALANCE_IN_PROGRESS(27, "The group is rebalancing, so a rejoin is needed.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new RebalanceInProgressException(message);
-            }
-        }),
+            RebalanceInProgressException::new),
     INVALID_COMMIT_OFFSET_SIZE(28, "The committing offset data size is not valid",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidCommitOffsetSizeException(message);
-            }
-        }),
+            InvalidCommitOffsetSizeException::new),
     TOPIC_AUTHORIZATION_FAILED(29, "Topic authorization failed.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new TopicAuthorizationException(message);
-            }
-        }),
+            TopicAuthorizationException::new),
     GROUP_AUTHORIZATION_FAILED(30, "Group authorization failed.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new GroupAuthorizationException(message);
-            }
-        }),
+            GroupAuthorizationException::new),
     CLUSTER_AUTHORIZATION_FAILED(31, "Cluster authorization failed.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new ClusterAuthorizationException(message);
-            }
-        }),
+            ClusterAuthorizationException::new),
     INVALID_TIMESTAMP(32, "The timestamp of the message is out of acceptable range.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidTimestampException(message);
-            }
-        }),
+            InvalidTimestampException::new),
     UNSUPPORTED_SASL_MECHANISM(33, "The broker does not support the requested SASL mechanism.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new UnsupportedSaslMechanismException(message);
-            }
-        }),
+            UnsupportedSaslMechanismException::new),
     ILLEGAL_SASL_STATE(34, "Request is not valid given the current SASL state.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new IllegalSaslStateException(message);
-            }
-        }),
+            IllegalSaslStateException::new),
     UNSUPPORTED_VERSION(35, "The version of API is not supported.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new UnsupportedVersionException(message);
-            }
-        }),
+            UnsupportedVersionException::new),
     TOPIC_ALREADY_EXISTS(36, "Topic with this name already exists.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new TopicExistsException(message);
-            }
-        }),
+            TopicExistsException::new),
     INVALID_PARTITIONS(37, "Number of partitions is below 1.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidPartitionsException(message);
-            }
-        }),
+            InvalidPartitionsException::new),
     INVALID_REPLICATION_FACTOR(38, "Replication factor is below 1 or larger than the number
of available brokers.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidReplicationFactorException(message);
-            }
-        }),
+            InvalidReplicationFactorException::new),
     INVALID_REPLICA_ASSIGNMENT(39, "Replica assignment is invalid.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidReplicaAssignmentException(message);
-            }
-        }),
+            InvalidReplicaAssignmentException::new),
     INVALID_CONFIG(40, "Configuration is invalid.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidConfigurationException(message);
-            }
-        }),
+            InvalidConfigurationException::new),
     NOT_CONTROLLER(41, "This is not the correct controller for this cluster.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new NotControllerException(message);
-            }
-        }),
+            NotControllerException::new),
     INVALID_REQUEST(42, "This most likely occurs because of a request being malformed by
the " +
                 "client library or the message was sent to an incompatible broker. See the
broker logs " +
                 "for more details.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidRequestException(message);
-            }
-        }),
+            InvalidRequestException::new),
     UNSUPPORTED_FOR_MESSAGE_FORMAT(43, "The message format version on the broker does not
support the request.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new UnsupportedForMessageFormatException(message);
-            }
-        }),
+            UnsupportedForMessageFormatException::new),
     POLICY_VIOLATION(44, "Request parameters do not satisfy the configured policy.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new PolicyViolationException(message);
-            }
-        }),
+            PolicyViolationException::new),
     OUT_OF_ORDER_SEQUENCE_NUMBER(45, "The broker received an out of order sequence number",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new OutOfOrderSequenceException(message);
-            }
-        }),
+            OutOfOrderSequenceException::new),
     DUPLICATE_SEQUENCE_NUMBER(46, "The broker received a duplicate sequence number",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new DuplicateSequenceException(message);
-            }
-        }),
+            DuplicateSequenceException::new),
     INVALID_PRODUCER_EPOCH(47, "Producer attempted an operation with an old epoch. Either
there is a newer producer " +
             "with the same transactionalId, or the producer's transaction has been expired
by the broker.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new ProducerFencedException(message);
-            }
-        }),
+            ProducerFencedException::new),
     INVALID_TXN_STATE(48, "The producer attempted a transactional operation in an invalid
state",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidTxnStateException(message);
-            }
-        }),
+            InvalidTxnStateException::new),
     INVALID_PRODUCER_ID_MAPPING(49, "The producer attempted to use a producer id which is
not currently assigned to " +
             "its transactional id",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidPidMappingException(message);
-            }
-        }),
+            InvalidPidMappingException::new),
     INVALID_TRANSACTION_TIMEOUT(50, "The transaction timeout is larger than the maximum value
allowed by " +
                 "the broker (as configured by transaction.max.timeout.ms).",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidTxnTimeoutException(message);
-            }
-        }),
+            InvalidTxnTimeoutException::new),
     CONCURRENT_TRANSACTIONS(51, "The producer attempted to update a transaction " +
                 "while another concurrent operation on the same transaction was ongoing",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new ConcurrentTransactionsException(message);
-            }
-        }),
+            ConcurrentTransactionsException::new),
     TRANSACTION_COORDINATOR_FENCED(52, "Indicates that the transaction coordinator sending
a WriteTxnMarker " +
             "is no longer the current coordinator for a given producer",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new TransactionCoordinatorFencedException(message);
-            }
-        }),
+            TransactionCoordinatorFencedException::new),
     TRANSACTIONAL_ID_AUTHORIZATION_FAILED(53, "Transactional Id authorization failed",
-                                                  new ApiExceptionBuilder() {
-        @Override
-        public ApiException build(String message) {
-            return new TransactionalIdAuthorizationException(message);
-        }
-    }),
-    SECURITY_DISABLED(54, "Security features are disabled.", new ApiExceptionBuilder() {
-        @Override
-        public ApiException build(String message) {
-            return new SecurityDisabledException(message);
-        }
-    }),
-    OPERATION_NOT_ATTEMPTED(55, "The broker did not attempt to execute this operation. This
may happen for batched RPCs " +
-            "where some operations in the batch failed, causing the broker to respond without
trying the rest.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new OperationNotAttemptedException(message);
-            }
-    }),
+            TransactionalIdAuthorizationException::new),
+    SECURITY_DISABLED(54, "Security features are disabled.",
+            SecurityDisabledException::new),
+    OPERATION_NOT_ATTEMPTED(55, "The broker did not attempt to execute this operation. This
may happen for " +
+            "batched RPCs where some operations in the batch failed, causing the broker to
respond without " +
+            "trying the rest.",
+            OperationNotAttemptedException::new),
     KAFKA_STORAGE_ERROR(56, "Disk error when trying to access log file on the disk.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new KafkaStorageException(message);
-            }
-    }),
+            KafkaStorageException::new),
     LOG_DIR_NOT_FOUND(57, "The user-specified log directory is not found in the broker config.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new LogDirNotFoundException(message);
-            }
-    }),
+            LogDirNotFoundException::new),
     SASL_AUTHENTICATION_FAILED(58, "SASL Authentication failed.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new SaslAuthenticationException(message);
-            }
-    }),
+            SaslAuthenticationException::new),
     UNKNOWN_PRODUCER_ID(59, "This exception is raised by the broker if it could not locate
the producer metadata " +
             "associated with the producerId in question. This could happen if, for instance,
the producer's records " +
             "were deleted because their retention time had elapsed. Once the last records
of the producerId are " +
             "removed, the producer's metadata is removed from the broker, and future appends
by the producer will " +
             "return this exception.",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new UnknownProducerIdException(message);
-            }
-    }),
+            UnknownProducerIdException::new),
     REASSIGNMENT_IN_PROGRESS(60, "A partition reassignment is in progress",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new ReassignmentInProgressException(message);
-            }
-        }),
-    DELEGATION_TOKEN_AUTH_DISABLED(61, "Delegation Token feature is not enabled.", new ApiExceptionBuilder()
{
-        @Override
-        public ApiException build(String message) {
-            return new DelegationTokenDisabledException(message);
-        }
-    }),
-    DELEGATION_TOKEN_NOT_FOUND(62, "Delegation Token is not found on server.", new ApiExceptionBuilder()
{
-        @Override
-        public ApiException build(String message) {
-            return new DelegationTokenNotFoundException(message);
-        }
-    }),
-    DELEGATION_TOKEN_OWNER_MISMATCH(63, "Specified Principal is not valid Owner/Renewer.",
new ApiExceptionBuilder() {
-        @Override
-        public ApiException build(String message) {
-            return new DelegationTokenOwnerMismatchException(message);
-        }
-    }),
-    DELEGATION_TOKEN_REQUEST_NOT_ALLOWED(64, "Delegation Token requests are not allowed on
PLAINTEXT/1-way SSL channels and " + "on delegation token authenticated channels.", new ApiExceptionBuilder()
{
-        @Override
-        public ApiException build(String message) {
-            return new UnsupportedByAuthenticationException(message);
-        }
-    }),
-    DELEGATION_TOKEN_AUTHORIZATION_FAILED(65, "Delegation Token authorization failed.", new
ApiExceptionBuilder() {
-        @Override
-        public ApiException build(String message) {
-            return new DelegationTokenAuthorizationException(message);
-        }
-    }),
-    DELEGATION_TOKEN_EXPIRED(66, "Delegation Token is expired.", new ApiExceptionBuilder()
{
-        @Override
-        public ApiException build(String message) {
-            return new DelegationTokenExpiredException(message);
-        }
-    }),
-    INVALID_PRINCIPAL_TYPE(67, "Supplied principalType is not supported", new ApiExceptionBuilder()
{
-        @Override
-        public ApiException build(String message) {
-            return new InvalidPrincipalTypeException(message);
-        }
-    }),
-    NON_EMPTY_GROUP(68, "The group is not empty", new ApiExceptionBuilder() {
-        @Override
-        public ApiException build(String message) {
-            return new GroupNotEmptyException(message);
-        }
-    }),
-    GROUP_ID_NOT_FOUND(69, "The group id does not exist", new ApiExceptionBuilder() {
-        @Override
-        public ApiException build(String message) {
-            return new GroupIdNotFoundException(message);
-        }
-    }),
+            ReassignmentInProgressException::new),
+    DELEGATION_TOKEN_AUTH_DISABLED(61, "Delegation Token feature is not enabled.",
+            DelegationTokenDisabledException::new),
+    DELEGATION_TOKEN_NOT_FOUND(62, "Delegation Token is not found on server.",
+            DelegationTokenNotFoundException::new),
+    DELEGATION_TOKEN_OWNER_MISMATCH(63, "Specified Principal is not valid Owner/Renewer.",
+            DelegationTokenOwnerMismatchException::new),
+    DELEGATION_TOKEN_REQUEST_NOT_ALLOWED(64, "Delegation Token requests are not allowed on
PLAINTEXT/1-way SSL " +
+            "channels and on delegation token authenticated channels.",
+            UnsupportedByAuthenticationException::new),
+    DELEGATION_TOKEN_AUTHORIZATION_FAILED(65, "Delegation Token authorization failed.",
+            DelegationTokenAuthorizationException::new),
+    DELEGATION_TOKEN_EXPIRED(66, "Delegation Token is expired.",
+            DelegationTokenExpiredException::new),
+    INVALID_PRINCIPAL_TYPE(67, "Supplied principalType is not supported",
+            InvalidPrincipalTypeException::new),
+    NON_EMPTY_GROUP(68, "The group is not empty",
+            GroupNotEmptyException::new),
+    GROUP_ID_NOT_FOUND(69, "The group id does not exist",
+            GroupIdNotFoundException::new),
     FETCH_SESSION_ID_NOT_FOUND(70, "The fetch session ID was not found",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new FetchSessionIdNotFoundException(message);
-            }
-    }),
+            FetchSessionIdNotFoundException::new),
     INVALID_FETCH_SESSION_EPOCH(71, "The fetch session epoch is invalid",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new InvalidFetchSessionEpochException(message);
-            }
-    }),
-    LISTENER_NOT_FOUND(72, "There is no listener on the leader broker that matches the listener
on which metadata request was processed",
-        new ApiExceptionBuilder() {
-            @Override
-            public ApiException build(String message) {
-                return new ListenerNotFoundException(message);
-            }
-    }),;
-
-    private interface ApiExceptionBuilder {
-        ApiException build(String message);
-    }
+            InvalidFetchSessionEpochException::new),
+    LISTENER_NOT_FOUND(72, "There is no listener on the leader broker that matches the listener
on which " +
+            "metadata request was processed",
+            ListenerNotFoundException::new),;
 
     private static final Logger log = LoggerFactory.getLogger(Errors.class);
 
@@ -652,13 +291,13 @@ public enum Errors {
     }
 
     private final short code;
-    private final ApiExceptionBuilder builder;
+    private final Function<String, ApiException> builder;
     private final ApiException exception;
 
-    Errors(int code, String defaultExceptionString, ApiExceptionBuilder builder) {
+    Errors(int code, String defaultExceptionString, Function<String, ApiException>
builder) {
         this.code = (short) code;
         this.builder = builder;
-        this.exception = builder.build(defaultExceptionString);
+        this.exception = builder.apply(defaultExceptionString);
     }
 
     /**
@@ -680,7 +319,7 @@ public enum Errors {
             return exception;
         }
         // Return an exception with the given error message.
-        return builder.build(message);
+        return builder.apply(message);
     }
 
     /**


Mime
View raw message