Sample

int-20454aa739fb-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines159

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5170–1; higher is more readable
Dorn0.0410–1; higher is more readable
Mi0.1190–1; higher is more readable
LLOC50Logical lines; fewer is more readable
DeepSeek V4 Pro10.330–20; mean of three runs
GPT-6.1 Sol130–20; mean of three runs
BTTF0.2590–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.info("Created connector {}", info.result().name()); } else { log.error("Failed to create connector for {}", connectorConfigFile); } }); 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)))) {} else { 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)))) { createConnectorRequest.config().put(NAME_CONFIG, createConnectorRequest.name()); } else { 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 + "'"); } } 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)))) {} else { 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.8569.337−282.788
Source linesThe number of non-empty source lines.159+63.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.755−7.133

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

Score0.517

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.160−4.629
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.180.981−4.001
Indentation frequencyHow rapidly indentation changes from line to line.136+3.967
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.136−2.7
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.180.969+2.115
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.158.984+1.812
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.076+0.208

Intercept 0.07 + feature contributions = -3.156 (log-odds).
Score = sigmoid(-3.156) = 0.041.

Score0.119
Score50
Run 1

The code shows moderate readability but has several issues. Structure is mostly logical with clear class hierarchy and methods, but some sections have confusing logic. The most significant problem is the inverted conditional pattern (e.g., `if (!((!condition))) {} else { ... }`) which obscures intent and makes code unnecessarily difficult to follow. Nesting depth is generally acceptable, but the parseConnectorConfigurationFile method is lengthy and combines multiple parsing strategies. The callback lambda in processExtraArgs is compact but hard to read due to inline conditionals. Some lines attempt multiple actions, reducing clarity. The method signatures are verbose but clear. Error handling is consistent. Action granularity suffers in places where multiple operations occur on single lines. Reading flow is disrupted by the unnatural conditional inversions. The code would benefit from extracting helper methods for validation logic and simplifying boolean expressions to improve readability.

Run 2

The code has basic structure with clear class purpose and method separation, but readability suffers significantly from several issues. The main problems are: (1) excessive use of negated conditionals with empty blocks like 'if (!((!connectorConfigs.containsKey(NAME_CONFIG)))) {} else {' which is extremely confusing and should be simplified to 'if (connectorConfigs.containsKey(NAME_CONFIG))'; (2) inconsistent brace style in lambda - some use braces some don't; (3) deeply nested lambda logic with ternary conditions making flow hard to follow; (4) duplicate logic for parsing connector configs creating unnecessary complexity; (5) long method signatures that span many lines without clear formatting; (6) mixed exception handling patterns with empty debug logging blocks. The code attempts to handle multiple file formats but the implementation obscures intent rather than clarifying it. Error handling creates ambiguity about which parsing strategy succeeded. Variable names are generally good and the Javadoc is helpful, but the actual implementation logic requires significant mental effort to understand.

Run 3

The code has clear structure at the class/method level, but readability is significantly reduced by awkward inverted conditionals (e.g., `if (!((!condition))) {} else { ... }`) and dense one-line lambda bodies with nested ternaries. Some methods like `processExtraArgs` mix multiple actions per line and rely on exceptions for control flow. While the parsing logic is broken into digestible steps, the intent is sometimes obscured by formatting choices and redundant comments. Import organization is flat but acceptable. Overall, the code functions but would benefit from cleaner conditionals, better line spacing, and more explicit error handling.

Run 1

Code Structure: Methods separate CLI setup, configuration parsing, and runtime construction logically, though parsing repeats validation. Nesting: Mostly shallow, but an avoidable nested else-if and empty conditional branches complicate control flow. Clarity of intent: Descriptive names and detailed documentation explain the purpose and parsing order; redundant negations such as !((!condition)) obscure straightforward checks. Code length: Generally appropriate, with some duplicated validation and verbose condition syntax. Action granularity: Most statements occupy separate lines, but the callback compresses an entire if/else and logging actions onto one line. Reading flow: Sequential parsing fallbacks and clear method boundaries support natural reading, while inconsistent indentation, tightly packed imports, empty branches, and convoluted conditions interrupt it.

Run 2

Code Structure: Methods separate CLI handling, configuration parsing, and runtime construction logically, though validation is duplicated. Nesting: Mostly shallow, but try/loop/lambda combinations and nested name checks add complexity. Clarity of intent: Descriptive names and detailed parsing documentation help, while redundant negations and empty success branches obscure straightforward conditions. Code length: Generally appropriate, with some avoidable repetition and verbose expressions. Action granularity: Most lines perform one action, but the callback compresses an entire if/else and logging operations onto one line. Reading flow: The documented JSON-to-properties fallback sequence is natural, but inconsistent formatting, long lines, and awkward conditional expressions interrupt scanning.

Run 3

Code Structure: Well-separated methods organize CLI startup, configuration parsing, and worker creation; parsing repeats name validation. Nesting: Mostly shallow, but try/loop/lambda blocks and nested name checks add complexity. Clarity of intent: Descriptive names and documentation explain the purpose, but redundant negations, excessive parentheses, and empty if branches obscure straightforward conditions. Code length: Generally proportionate to functionality, though duplicated validation and verbose conditional forms add unnecessary length. Action granularity: Most statements occupy separate lines, but the callback compresses an entire if/else and logging calls onto one line, hurting scanability. Reading flow: Startup and parsing fallback order are logical and documented; inconsistent formatting, crowded imports, and awkward conditionals interrupt an otherwise natural progression.