Sample

int-7a151194d5fd-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines101

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.4440–1; higher is more readable
Dorn0.6880–1; higher is more readable
Mi0.0510–1; higher is more readable
LLOC39Logical lines; fewer is more readable
DeepSeek V4 Pro90–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.4140–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()))) {} else { 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()))) {} else { 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()))) {} else { 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))) { if (isolation == FetchIsolation.HIGH_WATERMARK) return offsetSnapshot.highWatermark(); else return offsetSnapshot.lastStableOffset(); } else { return offsetSnapshot.logEndOffset(); } } @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()))) {} else { 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.5099.89−168.296
Source linesThe number of non-empty source lines.101+40.4
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.777−7.166

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

Score0.444

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.97+2.618
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.102−2.575
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.99−2.391
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.143+1.503
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.100.896+1
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.08+0.168

Intercept 0.07 + feature contributions = 0.791 (log-odds).
Score = sigmoid(0.791) = 0.688.

Score0.051
Score39
Run 1

The code has clear imports, meaningful method names, and documentation, but readability suffers due to several issues. The empty-if-else blocks in multiple methods (`if (!condition) {} else { ... }`) are confusing and should be simplified to direct condition checks. The `endOffsetMetadata` method uses tangled nested conditional logic that is hard to follow. Several lines exceed reasonable length, particularly the `fetchOffsetForTimestamp` calls and error messages. The repeated pattern for timestamp offset retrieval could be extracted into a helper method to reduce duplication across three very similar methods. While the class has a clear single responsibility and the helper method `partition()` reduces some duplication, the overall flow is disrupted by these structural issues, unnecessary complexity, and inconsistent formatting.

Run 2

The code has serious readability issues. The inverted if-else conditions with empty blocks (e.g., 'if (!((x.isEmpty()))) {} else { throw ... }') are confusing and non-idiomatic. The endOffsetMetadata method uses deeply nested conditional logic on a single line, making it hard to follow. While the class structure is logical and method names are clear, the implementation details contain unnecessary complexity. The importing of scala.Some and mixing it with Java Optional adds cognitive overhead. Action granularity is inconsistent - some lines combine multiple operations while others are properly separated. The repeated pattern of fetching timestamp offsets is somewhat repetitive but at least consistent. Overall, the code would be much more readable with standard if-else statements, early returns, and better formatting of nested conditions.

Run 3

The code has serious readability problems. While the class has a clear single responsibility and method names are descriptive, the implementation contains bizarre inverted conditional patterns like `if (!((timestampAndOffset.isEmpty()))) {} else { throw ... }` and `if (!((!partition.isLeader()))) {} else { ... }` that are confusing and unnecessarily convoluted. These empty if-blocks with else-throw logic reverse natural reading flow and should be simple `if (condition) throw` statements. The endOffsetMetadata method contains compressed nested if-else on single lines, violating action granularity and nesting depth guidelines. The offsetForEarliestTimestamp comment is helpful but the code structure around timestamp retrieval is verbose and repetitive across methods. The partition helper method's empty-if pattern further compounds the issue. Overall, the code appears to be deliberately obfuscated or poorly refactored, requiring significant mental effort to parse what should be straightforward validation and delegation logic.

Run 1

Code Structure: The class is logically organized into focused interface methods and a shared partition helper, although timestamp lookup logic is repeated. Nesting: Most methods are shallow, but endOffsetMetadata uses cramped nested conditionals that obscure branching. Clarity of intent: Descriptive method names, types, and comments explain the purpose; redundant parentheses, negated conditions, empty if branches, and double negation make checks unnecessarily difficult to interpret. Code length: Generally compact, but repeated lookup/error-handling blocks and verbose conditions add avoidable length. Action granularity: Most statements occupy separate lines, while endOffsetMetadata compresses multiple branches and returns onto single lines. Reading flow: Consistent method organization supports navigation, but inverted checks and inconsistent conditional formatting interrupt otherwise natural execution flow.

Run 2

Code Structure: Well-separated interface methods and a shared partition helper provide logical organization, although timestamp lookup logic is duplicated. Nesting: Mostly shallow, but endOffsetMetadata uses cramped nested conditionals that are unnecessarily difficult to follow. Clarity of intent: Descriptive method and variable names, comments, and exception messages explain the purpose; redundant parentheses, inverted conditions, and empty branches obscure otherwise simple checks. Code length: Generally reasonable, but repeated lookup/error-handling patterns and verbose conditional syntax add avoidable bulk. Action granularity: Most statements perform one action per line, but several branches and returns are compressed onto single lines. Reading flow: Methods follow a coherent progression and delegation is straightforward, but inconsistent formatting and negated control flow interrupt natural reading.

Run 3

Code Structure: Methods are logically separated by responsibility, with a shared partition lookup helper, but timestamp-fetch logic is repeated. Nesting: Generally shallow, although endOffsetMetadata uses awkward nested branching. Clarity of intent: Descriptive method names, types, and comments communicate purpose, but redundant parentheses, inverted conditions, double negation, and empty branches obscure straightforward checks. Code length: Reasonably compact overall, though repeated fetch-and-check sequences and unnecessarily elaborate conditionals add noise. Action granularity: Most statements occupy separate lines, but compressed braces and multiple branches on single lines undermine consistency. Reading flow: Method ordering and delegation are natural, while unusual conditional formatting, long expressions, and inconsistent import grouping interrupt scanning. Overall, the class is understandable, but its deliberately convoluted control flow significantly reduces readability.