Sample

int-95dd5b61c175-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines114

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.940–1; higher is more readable
Dorn0.6470–1; higher is more readable
Mi0.7140–1; higher is more readable
LLOC28Logical lines; fewer is more readable
DeepSeek V4 Pro6.670–20; mean of three runs
GPT-6.1 Sol13.330–20; mean of three runs
BTTF0.5450–1; higher is more readable

Views

Source code

package org.apache.kafka.common.utils; import java.time.Duration; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Supplier; /** * An interface abstracting the clock to use in unit testing classes that make use of clock time. * * Implementations of this class should be thread-safe. */ public interface Time { Time SYSTEM = SystemTime.getSystemTime(); /** * Returns the current time in milliseconds. */ long mil(); /** * Returns the value returned by `nanoseconds` converted into milliseconds. */ default long hi() { return TimeUnit.NANOSECONDS.toMillis(nan()); } /** * Returns the current value of the running JVM's high-resolution time source, in nanoseconds. * * <p>This method can only be used to measure elapsed time and is * not related to any other notion of system or wall-clock time. * The value returned represents nanoseconds since some fixed but * arbitrary <i>origin</i> time (perhaps in the future, so values * may be negative). The same origin is used by all invocations of * this method in an instance of a Java virtual machine; other * virtual machine instances are likely to use a different origin. */ long nan(); /** * Sleep for the given number of milliseconds */ void sle(long ms); /** * Wait for a condition using the monitor of a given object. This avoids the implicit * dependence on system time when calling {@link Object#wait()}. * * @param obj The object that will be waited with {@link Object#wait()}. Note that it is the responsibility * of the caller to call notify on this object when the condition is satisfied. * @param condition The condition we are awaiting * @param deadlineMs The deadline timestamp at which to raise a timeout error * * @throws org.apache.kafka.common.errors.TimeoutException if the timeout expires before the condition is satisfied */ default void wait(Object obj, Supplier<Boolean> con, long deadline) throws InterruptedException { synchronized (obj) { while (true) { if (con.get()) return; long current = mil(); if (current >= deadline) throw new org.apache.kafka.common.errors.TimeoutException("Condition not satisfied before deadline"); obj.wait(deadline - current); } } } /** * Get a timer which is bound to this time instance and expires after the given timeout */ default Timer tim(long timeout2) { return new Timer(this, timeout2); } /** * Get a timer which is bound to this time instance and expires after the given timeout */ default Timer tim(Duration tim) { return tim(tim.toMillis()); } /** * Wait for a future to complete, or time out. * * @param future The future to wait for. * @param deadlineNs The time in the future, in monotonic nanoseconds, to time out. * @return The result of the future. * @param <T> The type of the future. */ default <T> T wait2( Future<T> fut, long deadline2 ) throws TimeoutException, InterruptedException, ExecutionException { TimeoutException timeout = null; while (true) { long now = nan(); if (deadline2 <= now) { throw (timeout == null) ? new TimeoutException() : timeout; } long delta = deadline2 - now; try { return fut.get(delta, TimeUnit.NANOSECONDS); } catch (TimeoutException t) { timeout = t; } } } }

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.2096.68−69.19
Source linesThe number of non-empty source lines.114+45.6
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.384−6.577

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

Score0.94

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.115−3.035
Indentation frequencyHow rapidly indentation changes from line to line.73+1.788
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.120.983−1.459
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.113.934+1.183
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.120.991+1.148
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.044+0.516
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398

Intercept 0.07 + feature contributions = 0.608 (log-odds).
Score = sigmoid(0.608) = 0.647.

Score0.714
Score28
Run 1

The code has good documentation and a logical interface structure, but suffers from severe readability issues in naming and abstraction. Method names like 'mil()', 'nan()', 'sle()', 'tim()', and 'wait2()' are cryptic abbreviations that obscure intent. Parameter names like 'con', 'obj', 'fut', 'timeout2', and 'deadline2' are similarly ambiguous. The wait() method uses an infinite loop with multiple exit points, making control flow harder to follow. wait2() has complex timeout handling logic with a nullable TimeoutException variable, creating tangled flow. The import of java.time.Duration appears unused. While each method generally performs one action per line and nesting is moderate, the overall naming scheme and abbreviated identifiers significantly hamper clarity and maintainability. The code would benefit from descriptive names and clearer control flow patterns.

Run 2

The code is extremely difficult to read due to heavily abbreviated and non-descriptive method and parameter names (e.g., 'mil', 'nan', 'sle', 'con', 'tim', 'wait2', 'deadline2'). This severely obscures the intent of the code, despite the presence of Javadoc comments. The original naming from Kafka's Time interface (milliseconds, nanoseconds, sleep, waitObject) is concise but clear; replacing them with arbitrary abbreviations destroys clarity. Structure and nesting are acceptable, but the reading flow is broken by having to constantly map cryptic names to their meanings. The overall score is low primarily because code readability fundamentally depends on self-documenting names.

Run 3

The code has some structure with clear sections and Javadoc comments, but many method and parameter names are excessively abbreviated (mil, nan, sle, con, tim, wait2, fut, deadline2), obscuring intent. Comments do not compensate for ambiguous naming. The Time interface mixes several unrelated responsibilities (time retrieval, sleeping, condition waiting, future waiting), reducing logical organization. Some methods are reasonably flat, but wait2 contains a loop with nested try-catch and ternary throw, harming flow. Action granularity is mostly acceptable, though several lines combine multiple actions. The code is not excessively long but lacks consistency in naming style and clarity of purpose.

Run 1

Code Structure: Logically organized as a clock abstraction, with related operations grouped into small methods. Nesting: Mostly flat; synchronization, loops, and conditionals create moderate nesting in the waiting methods. Clarity of intent: Documentation explains the purpose, but abbreviated names such as mil, nan, sle, tim, con, and fut, plus arbitrary suffixes like wait2 and deadline2, obscure meaning. Several documentation parameter names do not match the signatures. Code length: Implementations are concise, though documentation is comparatively lengthy and timer comments repeat. Action granularity: Statements generally perform one action per line, making execution easy to follow. Reading flow: Consistent formatting and method separation support natural reading, but cryptic naming, omitted conditional braces, and the retry behavior in wait2 require extra interpretation.

Run 2

Code Structure: The interface logically groups clock access, sleeping, timers, and waiting, with small, focused methods. Nesting: Mostly shallow; the synchronized waiting loop and future retry loop introduce manageable nesting. Clarity of intent: Documentation explains behavior, but abbreviated names such as mil, nan, sle, tim, con, and fut obscure intent. Names like wait2, timeout2, and deadline2 are particularly uninformative. Several documentation parameter names do not match the actual signatures, and hi references a nonexistent nanoseconds method name. Code length: Implementations are concise; extensive documentation is generally useful rather than redundant. Action granularity: Statements typically perform one action per line, although the conditional exception expression requires slightly more interpretation. Reading flow: Method ordering and whitespace support natural reading, but inconsistent naming, omitted braces on some conditionals, and unusual signature formatting interrupt it.

Run 3

Code Structure: Methods are logically grouped in a small clock abstraction, with timing and waiting responsibilities clearly separated. Nesting: Mostly flat; the synchronized loop and conditional checks introduce moderate, manageable nesting. Clarity of intent: Documentation explains behavior well, but abbreviated names such as mil, nan, sle, tim, con, and wait2 obscure purpose. Several Javadoc parameter names do not match the actual signatures, reducing trust and clarity. Code length: Implementations are concise; lengthy documentation is generally useful rather than redundant. Action granularity: Statements typically perform one action per line, although the conditional exception expression requires extra interpretation. Reading flow: Consistent formatting and early returns support natural reading, but arbitrary numeric suffixes, omitted conditional braces, and inconsistent method-signature layout create friction.