Sample

int-d78a831cb630-I10

Remove about 40% of line-break groups while retaining structure

Matched original source

Lines106

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.3550–1; higher is more readable
Dorn0.0010–1; higher is more readable
Mi00–1; higher is more readable
LLOC50Logical lines; fewer is more readable
DeepSeek V4 Pro6.330–20; mean of three runs
GPT-6.1 Sol9.670–20; mean of three runs
BTTF0.0380–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); 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.8343.63−275.34
Source linesThe number of non-empty source lines.106+42.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.808−7.212

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

Score0.355

Feature contributions

FeatureValueContribution
(log-odds)
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.335.981−10.566
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.336+4.617
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.107−2.752
Indentation frequencyHow rapidly indentation changes from line to line.83+2.134
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.83−1.484
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.105.92+1.071
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.075+0.216

Intercept 0.07 + feature contributions = -6.695 (log-odds).
Score = sigmoid(-6.695) = 0.001.

Score0
Score50
Run 1

The code suffers from severe readability issues. Multiple statements are crammed onto single lines (especially in the imports and method declarations), making it extremely difficult to scan. There is inconsistent indentation and brace placement throughout, which breaks visual structure. Some methods like processExtraArgs and parseConnectorConfigurationFile are long and have multiple responsibilities, reducing clarity of intent. The exceptional flow with try-catch blocks that swallow exceptions and use log.debug instead of meaningful error handling adds ambiguity. Nesting depth is moderate, but the dense formatting makes the logic feel tangled. The action granularity is poor, with multiple actions per line and inconsistent spacing. Reading flow is unnatural due to the formatting inconsistencies. The class-level Javadoc is good, but method-level documentation is sparse. Overall, the code would greatly benefit from consistent formatting, better separation of concerns, and clearer error handling. This readability metric reflects both the formatting issues and the structural problems in the implementation.

Run 2

The code suffers from poor readability due to several factors. The import section is dense with multiple imports on single lines, making it hard to scan. Methods like processExtraArgs and parseConnectorConfigurationFile are overly long and contain deeply nested try-catch blocks. The conditional logic in processExtraArgs is compressed onto single lines (if/else on one line), violating the one-action-per-line principle. Error handling obscures the main logic flow. The parseConnectorConfigurationFile method attempts three different parsing strategies with unclear separation of concerns. While the class-level Javadoc is good, method-level documentation is inconsistent. The overall structure feels tangled, with high cognitive load required to trace execution paths through exception handling and nested conditionals.

Run 3

The code suffers from severe readability issues. Multiple statements are crammed onto single lines (e.g., imports, field declarations, method signatures), which violates the 'one action per line' principle and disrupts reading flow. The class-level Javadoc is clear, but method-level formatting is poor. The parseConnectorConfigurationFile method is very long, performing multiple parsing attempts with nested try-catch blocks and tangled logic, making it difficult to follow. Error handling and control flow feel disorganized. While identifiers and basic logic are understandable, the overall structure is harmed by inconsistent formatting and excessive line compression. The code would be far more readable with standard line breaks, separated declarations, and clearer method decomposition.

Run 1

1. Code Structure: Separate methods clearly divide CLI handling, configuration parsing, and worker creation, but compressed formatting obscures these boundaries. 2. Nesting: Mostly moderate, with deeper nesting in callbacks and connector-name validation; manageable but harder to follow due to inline braces. 3. Clarity of intent: Descriptive names, detailed documentation, and meaningful log messages explain the purpose and parsing order well. 4. Code length: Reasonable for its responsibilities, although repeated name validation adds minor duplication; long physical lines reduce scanability. 5. Action granularity: Frequently combines imports, declarations, method boundaries, and multiple executable statements on one line, substantially hurting readability. 6. Reading flow: The overall execution sequence and parsing fallbacks are logical, but inconsistent indentation, crowded annotations, and inline control flow repeatedly interrupt reading.

Run 2

1. Code Structure: Responsibilities are sensibly separated into startup, configuration parsing, and component creation methods, but compressed formatting obscures their boundaries. 2. Nesting: Mostly moderate, with deeper nesting in connector creation callbacks and configuration-name validation. 3. Clarity of intent: Descriptive names, useful documentation, and informative error messages explain the purpose and parsing fallback order. 4. Code length: Reasonably concise for its responsibilities, though repeated validation and lengthy signatures add some overhead; packing statements together does not improve readability. 5. Action granularity: Frequently poor: imports, declarations, method boundaries, and multiple executable statements share lines. 6. Reading flow: The underlying execution sequence is logical, but inconsistent indentation, inline braces, crowded annotations, and abrupt transitions force readers to reconstruct the structure. Overall, understandable logic and documentation are substantially undermined by formatting.

Run 3

Code Structure: Distinct methods logically separate CLI handling, configuration parsing, and worker setup, but compressed formatting obscures these boundaries. Nesting: Mostly moderate, with a loop, callback conditional, and nested configuration validation; not excessively deep. Clarity of intent: Descriptive names and useful Javadoc clearly explain the class and parsing fallback order. Code length: Reasonable for the functionality, although repeated mandatory-name validation adds some duplication. Action granularity: Frequently poor; imports, declarations, method boundaries, and multiple executable statements share lines. Reading flow: Sequential parsing attempts are understandable, but inconsistent indentation, inline braces, and crowded exception handlers disrupt scanning. Overall, the underlying organization is sound, but presentation substantially reduces readability.