Sample

int-ab32ff944260-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines162

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.840–1; higher is more readable
Dorn0.6670–1; higher is more readable
Mi0.0850–1; higher is more readable
LLOC50Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5620–1; higher is more readable

Views

Source code

package io.netty.util.concurrent; import io.netty.util.internal.ObjectUtil; /** * <p>A promise combiner monitors the outcome of a number of discrete futures, then notifies a final, aggregate promise * when all of the combined futures are finished. The aggregate promise will succeed if and only if all of the combined * futures succeed. If any of the combined futures fail, the aggregate promise will fail. The cause failure for the * aggregate promise will be the failure for one of the failed combined futures; if more than one of the combined * futures fails, exactly which cause of failure will be assigned to the aggregate promise is undefined.</p> * * <p>Callers may populate a promise combiner with any number of futures to be combined via the * {@link PromiseCombiner#add(Future)} and {@link PromiseCombiner#addAll(Future[])} methods. When all futures to be * combined have been added, callers must provide an aggregate promise to be notified when all combined promises have * finished via the {@link PromiseCombiner#finish(Promise)} method.</p> * * <p>This implementation is <strong>NOT</strong> thread-safe and all methods must be called * from the {@link EventExecutor} thread.</p> */ public final class PromiseCombiner { private int expectedCount; private int doneCount; private Promise<Void> aggregatePromise; private Throwable cause; private final GenericFutureListener<Future<?>> listener = new GenericFutureListener<Future<?>>() { @Override public void operationComplete(final Future<?> future) { if (executor.inEventLoop()) { operationComplete0(future); } else { executor.execute(new Runnable() { @Override public void run() { operationComplete0(future); } }); } } private void operationComplete0(Future<?> future) { assert executor.inEventLoop(); ++doneCount; if (!future.isSuccess() && cause == null) { cause = future.cause(); } if (doneCount == expectedCount && aggregatePromise != null) { tryPromise(); } } }; private final EventExecutor executor; /** * Deprecated use {@link PromiseCombiner#PromiseCombiner(EventExecutor)}. */ @Deprecated public PromiseCombiner() { this(ImmediateEventExecutor.INSTANCE); } /** * The {@link EventExecutor} to use for notifications. You must call {@link #add(Future)}, {@link #addAll(Future[])} * and {@link #finish(Promise)} from within the {@link EventExecutor} thread. * * @param executor the {@link EventExecutor} to use for notifications. */ public PromiseCombiner(EventExecutor executor) { this.executor = ObjectUtil.checkNotNull(executor, "executor"); } /** * Adds a new promise to be combined. New promises may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param promise the promise to add to this promise combiner * * @deprecated Replaced by {@link PromiseCombiner#add(Future)}. */ @Deprecated public void add(Promise promise) { add((Future) promise); } /** * Adds a new future to be combined. New futures may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param future the future to add to this promise combiner */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void add(Future future) { checkAddAllowed(); checkInEventLoop(); ++expectedCount; future.addListener(listener); } /** * Adds new promises to be combined. New promises may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param promises the promises to add to this promise combiner * * @deprecated Replaced by {@link PromiseCombiner#addAll(Future[])} */ @Deprecated public void addAll(Promise... promises) { addAll((Future[]) promises); } /** * Adds new futures to be combined. New futures may be added until an aggregate promise is added via the * {@link PromiseCombiner#finish(Promise)} method. * * @param futures the futures to add to this promise combiner */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void addAll(Future... futures) { for (Future future : futures) { this.add(future); } } /** * <p>Sets the promise to be notified when all combined futures have finished. If all combined futures succeed, * then the aggregate promise will succeed. If one or more combined futures fails, then the aggregate promise will * fail with the cause of one of the failed futures. If more than one combined future fails, then exactly which * failure will be assigned to the aggregate promise is undefined.</p> * * <p>After this method is called, no more futures may be added via the {@link PromiseCombiner#add(Future)} or * {@link PromiseCombiner#addAll(Future[])} methods.</p> * * @param aggregatePromise the promise to notify when all combined futures have finished */ public void finish(Promise<Void> aggregatePromise) { ObjectUtil.checkNotNull(aggregatePromise, "aggregatePromise"); checkInEventLoop(); if (this.aggregatePromise != null) { throw new IllegalStateException("Already finished"); } this.aggregatePromise = aggregatePromise; if (doneCount == expectedCount) { tryPromise(); } } private void checkInEventLoop() { if (!executor.inEventLoop()) { throw new IllegalStateException("Must be called from EventExecutor thread"); } } private boolean tryPromise() { return (cause == null) ? aggregatePromise.trySuccess(null) : aggregatePromise.tryFailure(cause); } private void checkAddAllowed() { if (aggregatePromise != null) { throw new IllegalStateException("Adding promises is not allowed after finished adding"); } } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.3071.679−101.365
Source linesThe number of non-empty source lines.162+64.8
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.575−6.862

Intercept 8.87 + feature contributions = -34.558 (log-odds).
Score = sigmoid(-34.558) = 0.

Score0.84

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.163−4.735
Indentation frequencyHow rapidly indentation changes from line to line.107+2.964
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.161.86+1.853
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.119.945−1.415
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.115.656+1.062
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.045+0.501
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398

Intercept 0.07 + feature contributions = 0.697 (log-odds).
Score = sigmoid(0.697) = 0.667.

Score0.085
Score50
Run 1

The code is well-structured with clear logical organization: fields, listener, constructors, public API methods, and private helpers are grouped sensibly. Nesting is generally flat, with the deepest level being three (listener -> operationComplete -> executor.execute -> Runnable), which is acceptable. Intent is explicit through meaningful names and thorough Javadoc. Code length is appropriate, though some deprecated overloads add slight verbosity. Action granularity is mostly one action per line, enhancing readability. Reading flow is natural, with public methods following constructors and private helpers at the end. Minor issues: the listener's nested Runnable slightly increases depth, and raw type usage with @SuppressWarnings detracts slightly from clarity.

Run 2

The code is well-structured and highly readable. It follows a logical organization, with fields grouped at the top, constructors, public API methods, and private helpers clearly separated. Nesting is minimal: the deepest nesting occurs in the listener callback, but it is justified by the asynchronous execution handling. Intent is clear due to descriptive method and variable names, along with comprehensive Javadoc comments explaining usage and constraints. Code length is reasonable, with no obvious redundancy except for the deprecated overloads, which are necessary for backward compatibility. Action granularity is mostly one action per line, though some dense lines (e.g., ternary in tryPromise, inline listener definition) slightly reduce readability. Reading flow is natural, with methods ordered from construction through usage to completion logic. Overall, the code is maintainable and understandable.

Run 3

The code is highly readable with clear structure and intent. The class has a single well-defined responsibility, and methods are logically organized with clear separation of concerns. Javadoc comments thoroughly explain usage, constraints, and edge cases. Nesting is mostly flat—the deepest nesting is two levels inside the listener, which is acceptable. Clarity of intent is strong due to descriptive method names like checkAddAllowed() and checkInEventLoop(). Code length is appropriate, avoiding unnecessary verbosity while maintaining completeness. Action granularity is mostly one action per line, though some conditionals combine operations. The reading flow is natural, moving from field declarations to constructors and public methods to private helpers. Minor deductions are for the anonymous listener class (which adds some indirection) and the deprecated methods that slightly clutter the public API.

Run 1

Code Structure: Well-organized class with focused methods and separate validation helpers, although the listener implementation interrupts the field declarations. Nesting: Most methods are flat; nested anonymous listener and Runnable classes add localized depth. Clarity of intent: Descriptive names and comprehensive documentation clearly explain aggregation, failure handling, and threading constraints; tryPromise is slightly vague. Code length: Implementation methods are concise, but repetitive Javadoc and deprecated overloads increase reading volume. Action granularity: Statements generally perform one action per line, with a compact, understandable ternary for completion. Reading flow: Consistent formatting and straightforward validation-to-action sequences support natural reading, though asynchronous callbacks and shared counters require some cross-referencing.

Run 2

Code Structure: Well organized into focused methods, with validation and completion logic separated. Nesting: Mostly shallow, although the listener containing an anonymous Runnable introduces noticeable nesting. Clarity of intent: Descriptive fields, method names, and thorough documentation clearly explain aggregation and thread constraints; tryPromise is slightly vague. Code length: Implementation methods are concise, but repetitive documentation and deprecated overloads increase reading overhead. Action granularity: Statements generally perform one action per line, making state changes easy to follow. Reading flow: Public operations and private helpers form a logical sequence, though the substantial listener near the top and asynchronous dispatch require readers to connect completion logic with add and finish. Overall, highly readable with modest verbosity and callback complexity.

Run 3

Code Structure: Well-organized class with focused public methods and extracted validation helpers, although the substantial listener implementation precedes constructors. Nesting: Most methods are flat; nested anonymous listener and Runnable classes add localized complexity. Clarity of intent: Descriptive names and comprehensive documentation clearly explain aggregation, failure handling, and threading requirements; operationComplete0 and tryPromise are less descriptive. Code length: Implementation methods are concise, but repetitive documentation and deprecated overloads increase overall length. Action granularity: Statements generally perform one action per line, making state changes and validation easy to follow. Reading flow: Consistent formatting and straightforward add/finish workflows support natural reading, though asynchronous callbacks, shared counters, and the listener's placement require some cross-referencing.