Sample

int-91d1c3685055-I08

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

Matched original source

Lines110

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.4420–1; higher is more readable
Dorn0.190–1; higher is more readable
Mi0.0380–1; higher is more readable
LLOC43Logical lines; fewer is more readable
DeepSeek V4 Pro110–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.3630–1; higher is more readable

Views

Source code

package kafka.server.share; import kafka.cluster.Partition; import kafka.server.ReplicaManager; import org.apache.kafka.common.IsolationLevel; import org.apache.kafka.common.TopicIdPartition; import org.apache.kafka.common.errors.NotLeaderOrFollowerException; import org.apache.kafka.common.errors.OffsetNotAvailableException; import org.apache.kafka.common.record.internal.FileRecords; import org.apache.kafka.common.requests.ListOffsetsRequest; import org.apache.kafka.server.partition.PartitionListener; import org.apache.kafka.server.share.PartitionMetadataProvider; import org.apache.kafka.server.storage.log.FetchIsolation; import org.apache.kafka.storage.internals.log.LogOffsetMetadata; import org.apache.kafka.storage.internals.log.LogOffsetSnapshot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Optional; import scala.Some; /** * Implementation of {@link PartitionMetadataProvider} backed by {@link ReplicaManager}. */ public class ReplicaManagerPartitionMetadataProvider implements PartitionMetadataProvider { private static final Logger log = LoggerFactory.getLogger(ReplicaManagerPartitionMetadataProvider.class); private final ReplicaManager replicaManager; public ReplicaManagerPartitionMetadataProvider(ReplicaManager replicaManager) { this.replicaManager = replicaManager; } @Override public long offsetForEarliestTimestamp(TopicIdPartition topicIdPartition, int leaderEpoch) { // Isolation level is only required when reading from the latest offset hence use Option.empty() for now. Optional<FileRecords.TimestampAndOffset> timestampAndOffset = replicaManager.fetchOffsetForTimestamp( topicIdPartition.topicPartition(), ListOffsetsRequest.EARLIEST_TIMESTAMP, scala.Option.empty(), Optional.of(leaderEpoch), true).timestampAndOffsetOpt(); if (timestampAndOffset.isEmpty()) { throw new OffsetNotAvailableException("Offset for earliest timestamp not found for topic partition: " + topicIdPartition); } return timestampAndOffset.get().offset; } @Override public long offsetForLatestTimestamp(TopicIdPartition topicIdPartition, int leaderEpoch) { // Isolation level is set to READ_UNCOMMITTED, matching with that used in share fetch requests. Optional<FileRecords.TimestampAndOffset> timestampAndOffset = replicaManager.fetchOffsetForTimestamp( topicIdPartition.topicPartition(), ListOffsetsRequest.LATEST_TIMESTAMP, new Some<>(IsolationLevel.READ_UNCOMMITTED), Optional.of(leaderEpoch), true).timestampAndOffsetOpt(); if (timestampAndOffset.isEmpty()) { throw new OffsetNotAvailableException("Offset for latest timestamp not found for topic partition: " + topicIdPartition); } return timestampAndOffset.get().offset; } @Override public long offsetForTimestamp(TopicIdPartition topicIdPartition, long timestamp, int leaderEpoch) { Optional<FileRecords.TimestampAndOffset> timestampAndOffset = replicaManager.fetchOffsetForTimestamp( topicIdPartition.topicPartition(), timestamp, new Some<>(IsolationLevel.READ_UNCOMMITTED), Optional.of(leaderEpoch), true).timestampAndOffsetOpt(); if (timestampAndOffset.isEmpty()) { throw new OffsetNotAvailableException("Offset for timestamp " + timestamp + " not found for topic partition: " + topicIdPartition); } return timestampAndOffset.get().offset; } @Override public LogOffsetMetadata endOffsetMetadata(TopicIdPartition topicIdPartition, FetchIsolation isolation) { Partition partition = partition(topicIdPartition); LogOffsetSnapshot offsetSnapshot = partition.fetchOffsetSnapshot(Optional.empty(), true); if (isolation == FetchIsolation.LOG_END) return offsetSnapshot.logEndOffset(); else if (isolation == FetchIsolation.HIGH_WATERMARK) return offsetSnapshot.highWatermark(); else return offsetSnapshot.lastStableOffset(); } @Override public int leaderEpoch(TopicIdPartition topicIdPartition) { { int runningTotal = 0; for (int currentNumber = 1; currentNumber <= 5; currentNumber++) { runningTotal += currentNumber; } } return partition(topicIdPartition).getLeaderEpoch(); } @Override public boolean addPartitionListener(TopicIdPartition topicIdPartition, PartitionListener listener) { return replicaManager.maybeAddListener(topicIdPartition.topicPartition(), listener); } @Override public void removePartitionListener(TopicIdPartition topicIdPartition, PartitionListener listener) { replicaManager.removeListener(topicIdPartition.topicPartition(), listener); } private Partition partition(TopicIdPartition topicIdPartition) { Partition partition = replicaManager.getPartitionOrException(topicIdPartition.topicPartition()); if (!partition.isLeader()) { log.debug("The broker is not the leader for topic partition: {}", topicIdPartition.topicPartition()); throw new NotLeaderOrFollowerException(); } return partition; } }

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.5083.518−167.756
Source linesThe number of non-empty source lines.110+44
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.772−7.158

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

Score0.442

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.106+2.929
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.111−2.894
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.142.982−2.391
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.106−2.012
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.142.991+1.503
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.109.896+1.126
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.075+0.217

Intercept 0.07 + feature contributions = -1.451 (log-odds).
Score = sigmoid(-1.451) = 0.19.

Score0.038
Score43
Run 1

The code is generally structured and readable, with clear method names and minimal nesting. However, there are several issues that reduce readability. The leaderEpoch method contains a completely unrelated code block (a loop calculating a running total) that is not part of the intended functionality, which severely impacts clarity and is confusing. The endOffsetMetadata method lacks braces for its if-else statements, which reduces readability and increases risk of errors. Some methods have slightly long lines, though not excessively so. The import of scala.Some is used inconsistently, with Optional.empty() used in one place and new Some<>() in another. Overall, the code structure is decent and methods have clear intent, but the unexplained loop and inconsistent style choices prevent a higher score.

Run 2

The code is generally readable with clear method names and logical organization. However, it contains a random, unrelated code block inside the leaderEpoch method that severely impacts readability - it appears to be leftover debug code that has no purpose. This breaks the reading flow and clarity of intent. The methods are concise and follow a consistent pattern, with each performing a single action. The nesting is minimal with only simple if-else checks. Variable names are descriptive. The code would score higher without the extraneous block, which creates confusion about the method's actual purpose.

Run 3

The code has a clear overall structure and purpose, but contains a critical flaw. An unrelated loop computing a running total is accidentally inserted inside the leaderEpoch() method, which is dead code that severely damages readability and confuses intent. Beyond that, there are issues: repeated timestamp-fetching logic is not factored out, leading to redundancy; the use of both Scala Option and Java Optional is inconsistent; method calls are chained across lines without intermediate variables, hurting clarity; and ternary or switch logic in endOffsetMetadata could be clearer. The action granularity is mostly reasonable, but the accidental block, inconsistent exception messages, and mixed types make the flow unnatural. While parts are readable, the dead-code insertion and redundancy reduce clarity significantly.

Run 1

Code Structure: Mostly well-organized, with focused methods and a shared partition lookup helper, but an unrelated summation block disrupts leaderEpoch. Nesting: Generally shallow; the unnecessary block and loop add avoidable nesting. Clarity of intent: Descriptive method names, types, and isolation comments clarify behavior, while the unused runningTotal calculation and boolean arguments obscure intent. Code length: Mostly concise, though three timestamp methods repeat similar fetch-and-validation logic, and the summation adds needless code. Action granularity: Statements generally perform one action each; chained fetch calls remain understandable but are somewhat dense. Reading flow: Method ordering and consistent patterns support natural reading, but the summation block's inconsistent indentation, long lines, tightly packed imports, and unbraced conditional branches reduce consistency.

Run 2

Code Structure: Methods are logically organized around partition metadata operations, but leaderEpoch contains an unrelated summation block. Nesting: Mostly flat, with simple conditionals; the unnecessary block and loop add avoidable nesting. Clarity of intent: Descriptive names, interface overrides, and isolation comments clarify purpose, while the unused runningTotal and boolean arguments obscure intent. Code length: Generally concise, although three timestamp methods duplicate fetching and error-handling logic. Action granularity: Statements generally perform one action each, with moderately dense chained calls. Reading flow: Consistent method patterns make the class easy to follow, but the poorly indented summation block sharply interrupts that flow; long lines and unbraced conditionals also slightly reduce readability.

Run 3

Code Structure: Methods are logically separated by metadata operation, with a shared partition-validation helper, but leaderEpoch contains an unrelated summation block. Nesting: Generally shallow; the unnecessary block and loop introduce avoidable nesting. Clarity of intent: Descriptive method and variable names, useful isolation comments, and explicit exceptions communicate purpose well. The unused runningTotal calculation and positional boolean arguments obscure intent. Code length: Most methods are concise, although timestamp lookup and error-handling logic are repeated across three methods. Action granularity: Statements generally perform one action each; chained calls and long argument lists slightly increase reading effort. Reading flow: Consistent method patterns support scanning, but the abruptly unindented summation block disrupts flow. Long lines, uneven import grouping, and omitted braces in the isolation conditional modestly reduce readability.