Sample

int-6eb4f60d6757-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines162

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5720–1; higher is more readable
Dorn0.0930–1; higher is more readable
Mi0.1190–1; higher is more readable
LLOC48Logical lines; fewer is more readable
DeepSeek V4 Pro15.330–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.3080–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() { 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); return new StandaloneHerder((new Worker(workerId, Time.SYSTEM, plugins, config, offsetBackingStore, connectorClientConfigOverridePolicy)), config.kafkaClusterId(), connectorClientConfigOverridePolicy); } @Override protected StandaloneConfig createConfig(Map<String, String> workerProps) { return new StandaloneConfig(workerProps); } public static void main(String[] args) { (new ConnectStandalone(args)).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.8281.097−273.276
Source linesThe number of non-empty source lines.162+64.8
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.731−7.097

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

Score0.572

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.163−4.735
Indentation frequencyHow rapidly indentation changes from line to line.139+4.071
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.139−2.769
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.975−2.56
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.161.98+1.854
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.146.086+1.553
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.073+0.236

Intercept 0.07 + feature contributions = -2.28 (log-odds).
Score = sigmoid(-2.28) = 0.093.

Score0.119
Score48
Run 1

The code is generally readable but has some weaknesses. Structure is logical, with clear class inheritance and method separation, but the parseConnectorConfigurationFile method is long and handles three different parsing strategies, reducing clarity. Nesting is mostly flat, with only a few single-level conditionals. Intent is clear for the main flow, but the parsing method’s multi-format logic and repeated catch-and-retry pattern make it harder to follow. Code length is acceptable overall but the parsing method could be refactored into smaller helper methods. Action granularity is mostly one action per line, though some lambda bodies and method calls are dense. Reading flow is natural for the main process but disrupted by the lengthy parsing logic and an unexplained blank line in createHerder. The use of magic values like `Exit.exit(3)` and the missing error variable in logging weakens clarity slightly.

Run 2

The code is well-structured with clear separation of concerns: argument processing, config file parsing, and herder creation are distinct methods. Nesting is mostly flat, except for a reasonable try/catch hierarchy. Intent is clearly expressed through descriptive method names and Javadoc. The code length is appropriate for the functionality, though the parsing method has some repetition. Action granularity is mostly good, with one logical operation per line. Reading flow is natural with clear try/catch blocks. Minor issues: some long parameter lists, vertically dense sections, and the parsing method could be split into smaller helper methods for the three different file format attempts. Slightly verbose imports and a blank line artifact in the herder method, but overall highly readable.

Run 3

The code is generally well-structured with clear method separation and reasonable naming. Imports are organized, and the class follows a logical flow (constructor, usage, processExtraArgs, parser, factory methods, main). The parsing method is somewhat long and contains three sequential try-catch blocks that make it harder to follow, though each attempt is documented. Nesting is minimal in most methods, but processExtraArgs has a lambda inside a loop inside a try-catch, adding moderate complexity. The lambda formatting is slightly condensed with if-else on one line, reducing readability. Intent is mostly clear, especially with Javadoc explaining parsing order. Code length is acceptable but parseConnectorConfigurationFile could be refactored into helper methods to improve granularity. Action granularity is mostly one-per-line, though the lambda body and createHerder constructor call pack multiple actions. Reading flow is natural overall but interrupted by the multi-attempt parsing strategy. The blank line in createHerder is a minor formatting issue. Overall, readable but could benefit from refactoring the parsing logic.

Run 1

Code Structure: Responsibilities are logically separated into startup, configuration parsing, and component creation methods, though parsing combines several formats and repeated validation. Nesting: Mostly shallow, with moderate nesting in the startup callback and connector-name validation. Clarity of intent: Descriptive names, useful Javadoc, and contextual logging make the purpose clear; abbreviated 'cb' and exception-driven parsing slightly reduce clarity. Code length: Generally appropriate, but duplicated mandatory-name checks and verbose construction expressions could be simplified. Action granularity: Most statements perform one action, although chained calls and nested constructor expressions require extra attention. Reading flow: Parsing follows a documented fallback sequence and startup proceeds naturally. Dense imports, inconsistent continuation indentation, stray blank lines, unnecessary parentheses, and unbraced conditionals detract from otherwise readable code.

Run 2

Code Structure: Well-separated methods organize CLI startup, connector parsing, and worker creation; parsing fallback stages are clearly ordered. Nesting: Mostly shallow, though the callback and nested connector-name validation add some complexity. Clarity of intent: Descriptive names, useful documentation, and contextual log messages explain the purpose well; the abbreviated callback variable 'cb' is less descriptive. Code length: Generally appropriate, but repeated mandatory-name validation and verbose constructor expressions introduce avoidable repetition. Action granularity: Most statements perform one action, although chained calls and nested object construction require extra effort to unpack. Reading flow: Execution and fallback parsing proceed naturally, supported by early returns. Inconsistent indentation, ungrouped imports, missing braces around callback branches, redundant parentheses, and stray blank lines slightly disrupt visual consistency.

Run 3

Code Structure: Well-separated methods organize CLI handling, configuration parsing, and runtime construction; parsing could be split into smaller helpers. Nesting: Mostly shallow, although the callback and connector-name validation introduce moderate nesting. Clarity of intent: Descriptive names, useful documentation, and explicit logging make the purpose clear; exception-driven format detection requires some attention. Code length: Generally proportionate to functionality, but repeated mandatory-name validation and verbose constructor expressions add avoidable length. Action granularity: Most statements perform one action, though nested construction and chained calls combine several operations. Reading flow: The documented JSON-to-properties fallback sequence is natural and easy to follow. Inconsistent indentation, ungrouped imports, stray blank lines, unnecessary parentheses, and omitted conditional braces slightly reduce visual consistency.