Sample

int-17f1a4a6b55b-I09

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

Matched original source

Lines105

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.4360–1; higher is more readable
Dorn0.1950–1; higher is more readable
Mi0.0380–1; higher is more readable
LLOC43Logical lines; fewer is more readable
DeepSeek V4 Pro10.330–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.1750–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) { {int lI0O_7c0e3240=0x871D;lI0O_7c0e3240=((lI0O_7c0e3240^0x871D)|0)&-1;if(((lI0O_7c0e3240&1)==1)){lI0O_7c0e3240^=lI0O_7c0e3240;}} 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.5196.475−171.484
Source linesThe number of non-empty source lines.105+42
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.847−7.271

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

Score0.436

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.101+2.756
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.106−2.717
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.972−2.391
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.101−1.897
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.142.972+1.502
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.104.854+1.056
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.076+0.201

Intercept 0.07 + feature contributions = -1.418 (log-odds).
Score = sigmoid(-1.418) = 0.195.

Score0.038
Score43
Run 1

The code is generally readable with clear method names and reasonable structure, but several issues reduce its score. The main problem is a suspicious obfuscated line in removePartitionListener that appears to be injected code - this severely damages trust and readability. Additionally, there's significant repetition across the three offset methods, each taking 8-10 lines for nearly identical logic. The endOffsetMetadata method uses if-else chains that could be cleaner with a switch statement. Method calls like fetchOffsetForTimestamp span multiple lines, making the flow harder to follow. The code does have good aspects: clear class purpose, descriptive variable names, and logical organization. However, the suspicious code block alone warrants significant penalty, and the repetitive patterns suggest refactoring is needed. The reading flow is generally natural except for the multi-line method calls and the injected line.

Run 2

The code has a clear class structure and generally follows a logical organization, but several factors reduce readability significantly. The repeated pattern of calling fetchOffsetForTimestamp, checking Optional emptiness, and throwing exceptions is duplicated across three methods, making the code unnecessarily long. The endOffsetMetadata method uses if-else branches on the FetchIsolation enum rather than a switch or separate methods. The most significant issue is the obfuscated dead code in the removePartitionListener method with variable lI0O_7c0e3240 that serves no purpose and severely disrupts reading flow. Comments are minimal, and while parameter/method names are descriptive, the long method invocations span multiple lines, making it harder to track arguments. Action granularity is generally one action per line, but the nested method calls and chained accessors like timestampAndOffsetOpt() followed by .isEmpty() checks add cognitive overhead. The class would benefit from extracting a helper method for timestamp offset retrieval and cleaning up the obfuscated code.

Run 3

The code is generally well-structured with clear class purpose, concise methods, and helpful comments. However, several issues reduce readability. The file contains an obfuscated, nonsensical line in the removePartitionListener method (a variable with an encoded name and no practical effect) that severely harms clarity and suggests injection of confusing code. Imports are not organized (no blank lines between related groups) and the file lacks formatting consistency. Method calls like fetchOffsetForTimestamp use mixed parameter styles and some long lines. While the helper partition() method centralizes logic and reduces duplication, error handling and intent are mostly clear. Overall, the code is understandable but includes distracting artifacts and inconsistent style that prevent a higher readability score.

Run 1

Code Structure: Methods are logically organized around partition metadata operations, with a useful shared partition helper. Nesting: Generally shallow, although removePartitionListener contains an unnecessary nested block and conditional. Clarity of intent: Descriptive names and isolation comments clarify most operations; the obfuscated variable and meaningless bitwise operations obscure intent. Code length: Mostly concise, but timestamp lookup methods repeat similar logic, and the injected block adds needless code. Action granularity: Most statements are cleanly separated; the obfuscated block packs multiple actions onto one line. Reading flow: Consistent delegation and straightforward error handling make most methods easy to follow, but the abrupt unformatted block disrupts readability. Long argument lists and brace-free conditional branches introduce minor additional friction.

Run 2

Code Structure: Methods are logically organized around metadata retrieval and listener management, with a shared partition-validation helper. Nesting: Most methods are flat, using simple conditionals and early exceptions; the injected block adds unnecessary nesting. Clarity of intent: Descriptive method names, types, and comments explain most operations, but the opaque variable and meaningless bitwise calculations in removePartitionListener obscure intent. Code length: Generally concise, though timestamp-fetching methods repeat similar logic and the injected block adds needless code. Action granularity: Most statements perform one action, but the injected block compresses several assignments and a conditional onto one line. Reading flow: Consistent formatting and predictable delegation make most code easy to follow; long calls, unbraced branches, and the abruptly unformatted block interrupt that flow.

Run 3

Code Structure: Methods are logically organized around partition metadata operations, but removePartitionListener contains an unrelated obfuscated block. Nesting: Most methods are flat, with simple guards and shallow conditional branches. Clarity of intent: Descriptive method and variable names, interface overrides, and useful comments make the main behavior clear; the cryptic variable and pointless bitwise operations obscure intent locally. Code length: Generally concise, although timestamp lookup methods repeat similar logic and the injected block adds unnecessary code. Action granularity: Most statements perform one action, but the obfuscated block compresses declarations, assignments, and a conditional onto one line. Reading flow: Consistent formatting and straightforward delegation support natural reading, interrupted sharply by the unindented block; long argument lists and brace-free conditionals add minor friction.