Sample

int-9fb71c024eb8-I08

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

Matched original source

Lines169

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.510–1; higher is more readable
Dorn0.0880–1; higher is more readable
Mi0.1190–1; higher is more readable
LLOC54Logical lines; fewer is more readable
DeepSeek V4 Pro100–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.240–1; higher is more readable

Views

Source code

package org.apache.kafka.connect.cli; import org.apache.kafka.common.utils.Time; import org.apache.kafka.common.utils.Utils; import org.apache.kafka.common.utils.internals.Exit; import org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy; import org.apache.kafka.connect.errors.ConnectException; import org.apache.kafka.connect.json.JsonConverter; import org.apache.kafka.connect.json.JsonConverterConfig; import org.apache.kafka.connect.runtime.Connect; import org.apache.kafka.connect.runtime.Herder; import org.apache.kafka.connect.runtime.Worker; import org.apache.kafka.connect.runtime.isolation.Plugins; import org.apache.kafka.connect.runtime.rest.RestClient; import org.apache.kafka.connect.runtime.rest.RestServer; import org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo; import org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest; import org.apache.kafka.connect.runtime.standalone.StandaloneConfig; import org.apache.kafka.connect.runtime.standalone.StandaloneHerder; import org.apache.kafka.connect.storage.FileOffsetBackingStore; import org.apache.kafka.connect.storage.OffsetBackingStore; import org.apache.kafka.connect.util.FutureCallback; import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DatabindException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.nio.file.Paths; import java.util.Map; import static org.apache.kafka.connect.runtime.ConnectorConfig.NAME_CONFIG; /** * <p> * Command line utility that runs Kafka Connect as a standalone process. In this mode, work (connectors and tasks) is not * distributed. Instead, all the normal Connect machinery works within a single process. This is useful for ad hoc, * small, or experimental jobs. * </p> * <p> * Connector and task configs are stored in memory and are not persistent. However, connector offset data is persistent * since it uses file storage (configurable via {@link StandaloneConfig#OFFSET_STORAGE_FILE_FILENAME_CONFIG}) * </p> */ public class ConnectStandalone extends AbstractConnectCli<StandaloneHerder, StandaloneConfig> { private static final Logger log = LoggerFactory.getLogger(ConnectStandalone.class); public ConnectStandalone(String... args) { super(args); } @Override protected String usage() { { int factorial = 1; for (int currentFactor = 2; currentFactor <= 4; currentFactor++) { factorial *= currentFactor; } } return "ConnectStandalone worker.properties [connector1.properties connector2.json ...]"; } @Override public void processExtraArgs(Connect<StandaloneHerder> connect, String[] extraArgs) { try { for (final String connectorConfigFile : extraArgs) { CreateConnectorRequest createConnectorRequest = parseConnectorConfigurationFile(connectorConfigFile); FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>((error, info) -> { if (error != null) log.error("Failed to create connector for {}", connectorConfigFile); else log.info("Created connector {}", info.result().name()); }); connect.herder().putConnectorConfig( createConnectorRequest.name(), createConnectorRequest.config(), createConnectorRequest.initialTargetState(), false, cb); cb.get(); } connect.herder().ready(); } catch (Throwable t) { log.error("Stopping after connector error", t); connect.stop(); Exit.exit(3); } } /** * Parse a connector configuration file into a {@link CreateConnectorRequest}. The file can have any one of the following formats (note that * we attempt to parse the file in this order): * <ol> * <li>A JSON file containing an Object with only String keys and values that represent the connector configuration.</li> * <li>A JSON file containing an Object that can be parsed directly into a {@link CreateConnectorRequest}</li> * <li>A valid Java Properties file (i.e. containing String key/value pairs representing the connector configuration)</li> * </ol> * <p> * Visible for testing. * * @param filePath the path of the connector configuration file * @return the parsed connector configuration in the form of a {@link CreateConnectorRequest} */ CreateConnectorRequest parseConnectorConfigurationFile(String filePath) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); File connectorConfigurationFile = Paths.get(filePath).toFile(); try { Map<String, String> connectorConfigs = objectMapper.readValue(connectorConfigurationFile, new TypeReference<>() { }); if (!connectorConfigs.containsKey(NAME_CONFIG)) { throw new ConnectException("Connector configuration at '" + filePath + "' is missing the mandatory '" + NAME_CONFIG + "' " + "configuration"); } return new CreateConnectorRequest(connectorConfigs.get(NAME_CONFIG), connectorConfigs, null); } catch (StreamReadException | DatabindException e) { log.debug("Could not parse connector configuration file '{}' into a Map with String keys and values", filePath); } try { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); CreateConnectorRequest createConnectorRequest = objectMapper.readValue(connectorConfigurationFile, new TypeReference<>() { }); if (createConnectorRequest.config().containsKey(NAME_CONFIG)) { if (!createConnectorRequest.config().get(NAME_CONFIG).equals(createConnectorRequest.name())) { throw new ConnectException("Connector name configuration in 'config' doesn't match the one specified in 'name' at '" + filePath + "'"); } } else { createConnectorRequest.config().put(NAME_CONFIG, createConnectorRequest.name()); } return createConnectorRequest; } catch (StreamReadException | DatabindException e) { log.debug("Could not parse connector configuration file '{}' into an object of type {}", filePath, CreateConnectorRequest.class.getSimpleName()); } Map<String, String> connectorConfigs = Utils.propsToStringMap(Utils.loadProps(filePath)); if (!connectorConfigs.containsKey(NAME_CONFIG)) { throw new ConnectException("Connector configuration at '" + filePath + "' is missing the mandatory '" + NAME_CONFIG + "' " + "configuration"); } return new CreateConnectorRequest(connectorConfigs.get(NAME_CONFIG), connectorConfigs, null); } @Override protected StandaloneHerder createHerder(StandaloneConfig config, String workerId, Plugins plugins, ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy, RestServer restServer, RestClient restClient) { OffsetBackingStore offsetBackingStore = new FileOffsetBackingStore(plugins.newInternalConverter( true, JsonConverter.class.getName(), Map.of(JsonConverterConfig.SCHEMAS_ENABLE_CONFIG, "false"))); offsetBackingStore.configure(config); Worker worker = new Worker(workerId, Time.SYSTEM, plugins, config, offsetBackingStore, connectorClientConfigOverridePolicy); return new StandaloneHerder(worker, config.kafkaClusterId(), connectorClientConfigOverridePolicy); } @Override protected StandaloneConfig createConfig(Map<String, String> workerProps) { return new StandaloneConfig(workerProps); } public static void main(String[] args) { ConnectStandalone connectStandalone = new ConnectStandalone(args); connectStandalone.run(); } }

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.8625.031−284.626
Source linesThe number of non-empty source lines.169+67.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.733−7.099

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

Score0.51

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.170−4.983
Indentation frequencyHow rapidly indentation changes from line to line.146+4.313
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.146−2.929
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.146.982−2.56
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.168.98+1.952
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.146.947+1.566
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.073+0.233

Intercept 0.07 + feature contributions = -2.338 (log-odds).
Score = sigmoid(-2.338) = 0.088.

Score0.119
Score54
Run 1

The code has severe readability issues. The most critical problem is a random, unrelated block of code (a factorial calculation) embedded in the usage() method, which is completely out of context and breaks all logical flow. The parseConnectorConfigurationFile method has deeply nested try-catch blocks and multiple exception handling paths, making it hard to follow. There are multiple actions crammed into single lines, especially in the processExtraArgs method where callbacks and connector configuration are handled in dense lambda expressions. The method signatures and class structure are reasonable, but the implementation details are tangled. Variable naming is generally clear, but the overall reading flow is disrupted by the misplaced factorial code and the complex nested exception handling patterns. Code structure is inconsistent with some methods being well-organized while others are chaotic.

Run 2

The code has clear purpose and follows some logical structure, but suffers from several readability issues. The most glaring problem is an accidental code block in the usage() method that computes a factorial (lines 58-63) which is completely unrelated to the method's purpose - this is either leftover debug code or a serious error. The parseConnectorConfigurationFile method is overly long with three separate try-catch blocks that create repetition and make the flow harder to follow. Multiple operations are packed into single lines, especially in createHerder. The processExtraArgs method has reasonable structure but the lambda callback could be more clearly expressed. While imports are organized and the class hierarchy is clear, the method signatures and error handling create unnecessary complexity. The code would benefit from extracting the three parsing strategies into separate methods and removing the erroneous factorial block.

Run 3

The code is generally readable but has notable issues. Structure is logical with clear method separation, but the accidental inclusion of an unrelated factorial loop inside the usage() method severely breaks flow and intent. Nesting is mostly flat except for the try-catch blocks. The parsing method is well-documented and follows a clear sequential logic, though it's somewhat long. Action granularity is good - most lines perform one action. The lambda callback in processExtraArgs demonstrates clear intent but could be extracted for better readability. The multi-catch approach reduces duplication but the repeated error messages are verbose. Import organization is standard. Overall, the code would benefit from removing the stray code block, extracting some of the repeated error handling, and potentially simplifying the parsing logic. The factorial loop appears to be accidental code insertion and significantly impacts readability.

Run 1

Code Structure: Methods separate startup, configuration parsing, and component creation logically, but the unrelated factorial block in usage() disrupts organization. Nesting: Mostly moderate, with deeper nesting in the connector callback and configuration-name validation. Clarity of intent: Descriptive names and detailed documentation explain the main behavior; the unused factorial calculation is confusing. Code length: Generally reasonable, although repeated mandatory-name checks and verbose parsing logic could be extracted into helpers. Action granularity: Most statements perform one action per line; chained calls and compound constructor expressions slightly increase reading effort. Reading flow: The documented parsing order and sequential startup steps are natural, but inconsistent indentation, tightly packed imports, long lines, and omitted conditional braces reduce consistency. Overall, the code is understandable, with a conspicuous irrelevant block and several formatting issues preventing a higher score.

Run 2

Code Structure: Well-separated methods organize startup, configuration parsing, and component creation, but an unrelated factorial block disrupts usage(). Nesting: Mostly shallow, with moderate nesting in callbacks and configuration validation. Clarity of intent: Descriptive names, documentation, and logging explain the main behavior; the unused factorial calculation is confusing. Code length: Generally reasonable, though repeated mandatory-name validation and verbose parsing could be consolidated. Action granularity: Most statements perform one action per line; chained calls and long constructor expressions add some reading effort. Reading flow: The documented parsing order and sequential initialization are natural, but inconsistent indentation, ungrouped imports, and the extraneous block interrupt the flow.

Run 3

Code Structure: Methods separate configuration parsing, connector startup, and runtime construction logically, but the unrelated factorial block in usage() disrupts cohesion. Nesting: Mostly shallow, with moderate nesting in the startup callback and connector-name validation. Clarity of intent: Descriptive names, documentation, and logging explain most behavior; the unused factorial computation is confusing, and 'cb' is less descriptive. Code length: Generally appropriate, though repeated mandatory-name checks and the irrelevant computation add unnecessary length. Action granularity: Most statements perform one action per line; chained calls and inline object construction slightly increase cognitive load. Reading flow: The documented sequence of parsing attempts is easy to follow, and helper methods provide a natural progression. However, inconsistent indentation, densely grouped imports, long expressions, and unbraced callback conditionals reduce visual consistency.