Sample

int-5c2de1fcc7bc-I10

Remove about 40% of line-break groups while retaining structure

Matched original source

Lines64

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.3120–1; higher is more readable
Dorn0.0010–1; higher is more readable
Mi00–1; higher is more readable
LLOC39Logical lines; fewer is more readable
DeepSeek V4 Pro5.670–20; mean of three runs
GPT-6.1 Sol11.330–20; mean of three runs
BTTF0.0860–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) { 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.4819.225−159.034
Source linesThe number of non-empty source lines.64+25.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.8−7.2

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

Score0.312

Feature contributions

FeatureValueContribution
(log-odds)
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.427−14.421
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.427+6.085
Indentation frequencyHow rapidly indentation changes from line to line.60+1.338
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.63−1.194
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.63.759+0.481
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.075+0.212

Intercept 0.07 + feature contributions = -7.031 (log-odds).
Score = sigmoid(-7.031) = 0.001.

Score0
Score39
Run 1

The code has serious readability issues. The most critical problem is inconsistent formatting: imports are crammed onto single lines, method signatures and bodies are compressed together, and opening braces share lines with other code. This destroys visual structure and makes the code appear tangled. Nesting is acceptable (shallow), and each method generally has a single clear purpose, but the formatting undermines clarity of intent. Code length is reasonable, though some method calls are unnecessarily verbose. Action granularity is violated: multiple statements appear on the same line (e.g., field declaration and constructor on one line). Reading flow is severely disrupted because code blocks are not visually separated, and the inconsistent style forces the reader to constantly parse dense line clusters. While the underlying logic is not complex, the presentation makes it difficult to scan and understand quickly. Proper formatting and line breaks alone could raise this significantly.

Run 2

The code suffers from severe readability issues. Imports are compressed onto single lines, and multiple statements frequently share lines, violating action granularity principles. The class and method declarations lack consistent formatting, with some braces on the same line as code and others improperly spaced. Method implementations are densely packed with long chained calls and minimal line breaks, making the logic difficult to follow. The endOffsetMetadata method uses an if-else chain without braces, creating ambiguity. Comments are brief but insufficient to offset the poor structure. The reading flow is disrupted by inconsistent indentation and crammed lines. While the class purpose is clear from its name and docstring, the implementation obscures intent through tangled, compressed code that requires significant effort to parse.

Run 3

The code has significant readability issues. Structure is inconsistent: imports, method declarations, and braces are frequently on the same line, making it hard to scan. Nesting is mostly shallow, but formatting makes it feel cluttered. Intent is mostly clear, though method names are descriptive. Code length is reasonable but appears verbose due to formatting. Action granularity is poor—multiple statements and control flow are packed together. Reading flow is disrupted by dense lines and inconsistent whitespace. The core logic is simple, but presentation severely hurts clarity.

Run 1

Code Structure: Methods are logically separated by responsibility, but compressed imports, declarations, and method boundaries obscure organization. Nesting: Mostly shallow, with simple guards and a short conditional chain. Clarity of intent: Descriptive method and variable names, explanatory comments, and specific exceptions make the purpose clear. Code length: Reasonably concise, although timestamp-fetching methods repeat similar logic and error handling. Action granularity: Multiple imports, statements, and control-flow elements frequently share a line, reducing readability. Reading flow: Inconsistent indentation, long lines, crowded annotations, and inline braces interrupt scanning. Overall, the underlying design is understandable, but poor formatting substantially weakens readability.

Run 2

Code Structure: Responsibilities are logically separated into focused methods, but compressed imports, declarations, and braces obscure organization. Nesting: Shallow conditionals and early exceptions keep complexity low. Clarity of intent: Descriptive method and variable names, interface overrides, and useful comments make the purpose clear; positional boolean arguments are less obvious. Code length: Methods are short, though timestamp lookup and exception handling are repeated. Action granularity: Multiple imports, declarations, conditionals, throws, and returns share lines, making individual actions harder to distinguish. Reading flow: Inconsistent indentation, line breaks, and brace placement interrupt scanning, especially in timestamp methods and isolation selection. Overall, the underlying logic is straightforward, but poor formatting substantially reduces readability.

Run 3

Code Structure: Responsibilities are logically separated into focused methods, with a shared partition lookup helper. Nesting: Mostly flat, with simple checks and a short conditional chain. Clarity of intent: Descriptive method names, domain-specific types, and useful isolation-level comments make the purpose clear. Code length: Methods are short, though timestamp lookup and exception handling are repeated. Action granularity: Multiple imports, declarations, conditionals, throws, and returns frequently share lines, making individual actions harder to distinguish. Reading flow: Inconsistent indentation, compressed method boundaries, inline annotations, and omitted conditional braces disrupt scanning. The underlying organization is readable, but formatting significantly reduces accessibility.