Sample

int-468c64e5ac92-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines103

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.4880–1; higher is more readable
Dorn0.7670–1; higher is more readable
Mi0.0390–1; higher is more readable
LLOC39Logical lines; fewer is more readable
DeepSeek V4 Pro90–20; mean of three runs
GPT-6.1 Sol13.670–20; mean of three runs
BTTF0.4360–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 replica) { this.replicaManager = replica; } @Override public long offset(TopicIdPartition topic, int leader) { // Isolation level is only required when reading from the latest offset hence use Option.empty() for now. Optional<FileRecords.TimestampAndOffset> timestamp2 = replicaManager.fetchOffsetForTimestamp( topic.topicPartition(), ListOffsetsRequest.EARLIEST_TIMESTAMP, scala.Option.empty(), Optional.of(leader), true).timestampAndOffsetOpt(); if (timestamp2.isEmpty()) { throw new OffsetNotAvailableException("Offset for earliest timestamp not found for topic partition: " + topic); } return timestamp2.get().offset; } @Override public long offset2(TopicIdPartition topic2, int leader2) { // Isolation level is set to READ_UNCOMMITTED, matching with that used in share fetch requests. Optional<FileRecords.TimestampAndOffset> timestamp3 = replicaManager.fetchOffsetForTimestamp( topic2.topicPartition(), ListOffsetsRequest.LATEST_TIMESTAMP, new Some<>(IsolationLevel.READ_UNCOMMITTED), Optional.of(leader2), true).timestampAndOffsetOpt(); if (timestamp3.isEmpty()) { throw new OffsetNotAvailableException("Offset for latest timestamp not found for topic partition: " + topic2); } return timestamp3.get().offset; } @Override public long offset3(TopicIdPartition topic3, long tim, int leader3) { Optional<FileRecords.TimestampAndOffset> timestamp = replicaManager.fetchOffsetForTimestamp( topic3.topicPartition(), tim, new Some<>(IsolationLevel.READ_UNCOMMITTED), Optional.of(leader3), true).timestampAndOffsetOpt(); if (timestamp.isEmpty()) { throw new OffsetNotAvailableException("Offset for timestamp " + tim + " not found for topic partition: " + topic3); } return timestamp.get().offset; } @Override public LogOffsetMetadata end(TopicIdPartition topic4, FetchIsolation iso) { Partition par = par(topic4); LogOffsetSnapshot offset2 = par.fetchOffsetSnapshot(Optional.empty(), true); if (iso == FetchIsolation.LOG_END) return offset2.logEndOffset(); else if (iso == FetchIsolation.HIGH_WATERMARK) return offset2.highWatermark(); else return offset2.lastStableOffset(); } @Override public int leader(TopicIdPartition topic5) { return par(topic5).getLeaderEpoch(); } @Override public boolean add(TopicIdPartition topic6, PartitionListener lis) { return replicaManager.maybeAddListener(topic6.topicPartition(), lis); } @Override public void remove(TopicIdPartition topic7, PartitionListener lis2) { replicaManager.removeListener(topic7.topicPartition(), lis2); } private Partition par(TopicIdPartition topic8) { Partition par2 = replicaManager.getPartitionOrException(topic8.topicPartition()); if (!par2.isLeader()) { log.debug("The broker is not the leader for topic partition: {}", topic8.topicPartition()); throw new NotLeaderOrFollowerException(); } return par2; } }

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.4928−162.624
Source linesThe number of non-empty source lines.103+41.2
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.801−7.201

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

Score0.488

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.99+2.687
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.104−2.646
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.126.971−1.713
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.125.74+1.224
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.102.828+1.028
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.082+0.146

Intercept 0.07 + feature contributions = 1.194 (log-odds).
Score = sigmoid(1.194) = 0.767.

Score0.039
Score39
Run 1

The code has a clear purpose as an implementation of PartitionMetadataProvider, but readability suffers from poor naming (offset, offset2, offset3, topic, topic2, topic3, par, par2) which obscures intent. Method names do not convey what each variant does (earliest vs latest vs timestamp). The structure is logical but repetitive, with duplicated validation and exception handling. Nesting is minimal, which is good, but the long method chains mixed with Optional checks reduce clarity. Action granularity is moderate — some lines pack multiple operations. Reading flow is disrupted by inconsistent variable suffixes and ambiguous method names. Overall, the logic is understandable but could be greatly improved with descriptive method names (e.g., earliestOffset, latestOffset) and consistent variable names.

Run 2

The code has significant readability issues. Variable naming is confusing and non-descriptive: `timestamp2`, `topic2`, `leader2`, `topic3`, `tim`, `topic4`, `par2`, etc. The suffix conventions suggest code was auto-generated or copy-pasted, making it hard to understand intent. Method names like `offset`, `offset2`, `offset3` are ambiguous. The `end` method uses an if-else chain that could be a switch expression, and the private `par` method abbreviates unnecessarily. Nesting is acceptable, but reading flow is disrupted by poor naming and inconsistent naming patterns. Some comments help, but the core implementation lacks clarity. Structure is logical due to the interface, but action granularity and code length are reasonable. Overall, the code is functional but not self-documenting; a reader must infer meaning from context rather than names.

Run 3

The code suffers from poor readability despite straightforward logic. Variable naming is confusing (timestamp2, topic3, offset2, par2) suggesting careless renaming rather than meaningful identifiers. Method names like offset(), offset2(), offset3() and end() are ambiguous and fail to convey their distinct purposes. The code structure is mostly flat, but the end() method uses nested if-else chains. Multiple actions occur per line in several places, and the 'magic' boolean parameter 'true' appears repeatedly without explanation. Reading flow is disrupted by inconsistent naming patterns and redundant local variables. The class-level documentation is minimal, and critical parameters like isolation levels are only briefly commented inline. Overall, the implementation appears to have been generated or hastily modified, leaving artifacts that obscure intent rather than communicating it clearly to readers.

Run 1

Code Structure: The class is logically organized into short provider methods and a shared partition-validation helper, although timestamp lookup logic is repeated. Nesting: Control flow is shallow, with simple guards and one straightforward conditional chain. Clarity of intent: This is the main weakness; names such as offset2, offset3, par, tim, and numbered parameters obscure distinct responsibilities. API calls, exception messages, and isolation comments partially clarify behavior. Code length: Generally concise, though the three offset methods duplicate fetching and validation. Action granularity: Statements generally perform one action per line; wrapped method calls remain understandable. Reading flow: Methods follow a coherent sequence, but generic names, missing braces in the isolation conditional, and tightly grouped imports reduce scanability. Overall, the implementation is easy to trace locally but requires extra effort to understand its public operations.

Run 2

Code Structure: Methods are logically separated, with a shared partition lookup helper, though offset-fetching logic is repeated. Nesting: Shallow conditionals and straightforward returns make execution paths easy to follow. Clarity of intent: Kafka types, comments, and exception messages provide context, but names such as offset2, offset3, par, tim, and numbered parameters obscure distinctions and responsibilities. Code length: Generally concise, although the three similar offset methods add duplication. Action granularity: Statements mostly perform one action per line; multiline chained calls remain manageable. Reading flow: Consistent formatting and simple method bodies support natural reading, but abbreviated names, numbered identifiers, ungrouped imports, and omitted braces in the isolation conditional reduce readability.

Run 3

Code Structure: Methods are logically separated, with a shared partition lookup helper, though offset retrieval repeats similar logic. Nesting: Shallow conditionals and early exceptions keep complexity low. Clarity of intent: API calls, comments, and exception messages explain behavior, but names such as offset2, offset3, par, tim, and numbered parameters obscure important distinctions. Code length: Generally concise, with some duplication across offset methods. Action granularity: Statements mostly perform one action per line; chained calls are manageable. Reading flow: Consistent method formatting and straightforward control flow help, but missing braces in end(), minimally separated imports, and vague naming interrupt comprehension.