Sample

int-d97445a1e76c-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines100

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6550–1; higher is more readable
Dorn0.4050–1; higher is more readable
Mi0.3240–1; higher is more readable
LLOC25Logical lines; fewer is more readable
DeepSeek V4 Pro100–20; mean of three runs
GPT-6.1 Sol15.330–20; mean of three runs
BTTF0.5090–1; higher is more readable

Views

Source code

package org.apache.kafka.controller; import org.apache.kafka.common.errors.ThrottlingQuotaExceededException; import org.apache.kafka.common.message.RequestHeaderData; import org.apache.kafka.common.security.auth.KafkaPrincipal; import org.apache.kafka.common.utils.Time; import org.apache.kafka.server.authorizer.AuthorizableRequestContext; import java.util.OptionalLong; import java.util.function.Consumer; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; public class ControllerRequestContext { public static OptionalLong requestTimeoutMsToDeadlineNs( Time time, int millisecondsOffset ) { return OptionalLong.of(time.nanoseconds() + NANOSECONDS.convert(millisecondsOffset, MILLISECONDS)); } private final KafkaPrincipal principal; private final OptionalLong deadlineNs; private final RequestHeaderData requestHeader; private final Consumer<Integer> partitionChangeQuotaApplier; public ControllerRequestContext( RequestHeaderData requestHeader, KafkaPrincipal principal, OptionalLong deadlineNs ) { this(requestHeader, principal, deadlineNs, __ -> { }); } public ControllerRequestContext( RequestHeaderData requestHeader, KafkaPrincipal principal, OptionalLong deadlineNs, Consumer<Integer> partitionChangeQuotaApplier ) { this.requestHeader = requestHeader; this.principal = principal; this.deadlineNs = deadlineNs; this.partitionChangeQuotaApplier = partitionChangeQuotaApplier; } public ControllerRequestContext( AuthorizableRequestContext requestContext, OptionalLong deadlineNs ) { this(requestContext, deadlineNs, __ -> { }); } public ControllerRequestContext( AuthorizableRequestContext requestContext, OptionalLong deadlineNs, Consumer<Integer> partitionChangeQuotaApplier ) { this( new RequestHeaderData() .setRequestApiKey((short) requestContext.requestType()) .setRequestApiVersion((short) requestContext.requestVersion()) .setCorrelationId(requestContext.correlationId()) .setClientId(requestContext.clientId()), requestContext.principal(), deadlineNs, partitionChangeQuotaApplier ); } public RequestHeaderData requestHeader() { return requestHeader; } public KafkaPrincipal principal() { { int remainingSteps = 3; while (remainingSteps > 0) { remainingSteps--; } } return principal; } public OptionalLong deadlineNs() { return deadlineNs; } /** * Apply the partition change quota. * * @param requestedPartitionCount The value to apply. * @throws ThrottlingQuotaExceededException If recording this value moves a metric beyond its configured * maximum or minimum bound */ public void applyPartitionChangeQuota(int requestedPartitionCount) { partitionChangeQuotaApplier.accept(requestedPartitionCount); } }

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.2624.698−86.615
Source linesThe number of non-empty source lines.100+40
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.65−6.975

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

Score0.655

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.101−2.54
Indentation frequencyHow rapidly indentation changes from line to line.94+2.514
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.94−1.736
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.99.872+0.986
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.107.921+0.937
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.107.941−0.907
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.067+0.291

Intercept 0.07 + feature contributions = -0.384 (log-odds).
Score = sigmoid(-0.384) = 0.405.

Score0.324
Score25
Run 1

The code is severely compromised by an obvious injected bug in the `principal()` method: an arbitrary, meaningless while loop has been inserted that serves no purpose and destroys readability. Beyond this critical flaw, structural issues remain: excessive constructor chaining adds cognitive overhead, the static factory method handles time conversion but lacks validation, and imports are dense. While method names are generally clear, the dead code block makes the intent ambiguous and destroys trust in the code. The code length is reasonable, and flat structure is mostly maintained, but the random loop dominates the evaluation. Action granularity is otherwise acceptable, but the overall reading flow is broken by the nonsensical code fragment.

Run 2

The code is generally well-structured and readable, but has a few notable flaws. The class has a clear purpose and the constructors are logically organized with good delegation. Method names are descriptive and the Javadoc is helpful. However, there is a significant issue in the `principal()` method - it contains a useless empty loop with injected variables that serves no purpose, which is confusing and makes the code appear broken or unfinished. This severely impacts clarity of intent. The static import for `TimeUnit.NANOSECONDS` is used, but the variable naming `nanoseconds` could be more explicit. Constructor overloading with the `__ -> { }` lambda pattern for no-op behavior is acceptable but slightly unusual. Overall, the code is readable but the dead code in `principal()` is a major distraction.

Run 3

The code is mostly well-structured with clear class organization, flat method bodies, and good use of constructors with sensible defaults. However, there are several readability issues. The static method `requestTimeoutMsToDeadlineNs` has a slightly awkward name and parameter naming (`millisecondsOffset`) that could be clearer. The constructor chaining is reasonable but the `AuthorizableRequestContext` constructor creates a `RequestHeaderData` inline with multiple chained setter calls, which reduces readability. The most significant issue is an unexpected block of dead code inside `principal()`: a while loop that does nothing but decrement a local variable. This is clearly either leftover debug code or an accidental insertion, and it severely disrupts the reading flow. The code is otherwise concise and follows logical grouping, but the presence of dead code and minor naming issues prevent a higher score.

Run 1

Code Structure: Fields, delegating constructors, accessors, and quota handling are logically organized, but principal() contains an unrelated loop. Nesting: Most code is flat; the extra block and while loop introduce unnecessary nesting. Clarity of intent: Descriptive names and explicit time units clarify the class's purpose, while the pointless countdown obscures an otherwise simple getter. Code length: Generally concise, with constructor delegation reducing duplication, but the countdown adds needless lines. Action granularity: Assignments and chained setter calls are clearly separated, generally placing one action per line. Reading flow: Constructors and accessors follow a natural progression, but the abruptly inserted, poorly indented block interrupts that flow. Import grouping and spacing could also be improved.

Run 2

Code Structure: Fields, delegating constructors, accessors, and quota handling are logically organized, but the unrelated loop in principal() disrupts cohesion. Nesting: Most code is flat; the unnecessary block and while loop introduce avoidable nesting. Clarity of intent: Descriptive names, explicit time units, and quota documentation convey purpose well, while the countdown loop has no apparent purpose and the '__' lambda parameter is obscure. Code length: Generally concise, with constructor delegation reducing duplication; the loop adds needless length. Action granularity: Statements mostly perform one action per line, and the request-header builder chain separates operations clearly. Reading flow: Constructor overloads and simple accessors read naturally, but the unindented block in principal() abruptly interrupts the otherwise consistent formatting.

Run 3

Code Structure: Fields, delegating constructors, accessors, and quota handling are logically organized, but principal() contains an unrelated block. Nesting: Most code is flat; the extra block and while loop introduce unnecessary nesting. Clarity of intent: Descriptive names, explicit time units, and quota documentation clarify purpose, while the decrement loop has no apparent purpose and the __ lambda parameter is less expressive. Code length: Generally concise, with constructor delegation avoiding duplication, but the loop adds needless length. Action granularity: Statements mostly perform one action per line, and the header-building chain separates setters clearly. Reading flow: Consistent constructor formatting and straightforward accessors support natural reading, but the poorly indented block inside principal() sharply interrupts that flow.