Sample

int-c7d1c0d44224-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines162

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5530–1; higher is more readable
Dorn0.0950–1; higher is more readable
Mi0.1190–1; higher is more readable
LLOC50Logical lines; fewer is more readable
DeepSeek V4 Pro5.670–20; mean of three runs
GPT-6.1 Sol130–20; mean of three runs
BTTF0.2810–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... arg) { super(arg); } @Override protected String usa() { return "ConnectStandalone worker.properties [connector1.properties connector2.json ...]"; } @Override public void process(Connect<StandaloneHerder> con, String[] extra) { try { for (final String connector2 : extra) { CreateConnectorRequest create = parse(connector2); FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>((err, inf) -> { if (err != null) log.error("Failed to create connector for {}", connector2); else log.info("Created connector {}", inf.result().name()); }); con.herder().putConnectorConfig( create.name(), create.config(), create.initialTargetState(), false, cb); cb.get(); } con.herder().ready(); } catch (Throwable t) { log.error("Stopping after connector error", t); con.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 parse(String file2) throws IOException { ObjectMapper object = new ObjectMapper(); File connector3 = Paths.get(file2).toFile(); try { Map<String, String> connector4 = object.readValue(connector3, new TypeReference<>() { }); if (!connector4.containsKey(NAME_CONFIG)) { throw new ConnectException("Connector configuration at '" + file2 + "' is missing the mandatory '" + NAME_CONFIG + "' " + "configuration"); } return new CreateConnectorRequest(connector4.get(NAME_CONFIG), connector4, null); } catch (StreamReadException | DatabindException e) { log.debug("Could not parse connector configuration file '{}' into a Map with String keys and values", file2); } try { object.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); CreateConnectorRequest create2 = object.readValue(connector3, new TypeReference<>() { }); if (create2.config().containsKey(NAME_CONFIG)) { if (!create2.config().get(NAME_CONFIG).equals(create2.name())) { throw new ConnectException("Connector name configuration in 'config' doesn't match the one specified in 'name' at '" + file2 + "'"); } } else { create2.config().put(NAME_CONFIG, create2.name()); } return create2; } catch (StreamReadException | DatabindException e) { log.debug("Could not parse connector configuration file '{}' into an object of type {}", file2, CreateConnectorRequest.class.getSimpleName()); } Map<String, String> connector5 = Utils.propsToStringMap(Utils.loadProps(file2)); if (!connector5.containsKey(NAME_CONFIG)) { throw new ConnectException("Connector configuration at '" + file2 + "' is missing the mandatory '" + NAME_CONFIG + "' " + "configuration"); } return new CreateConnectorRequest(connector5.get(NAME_CONFIG), connector5, null); } @Override protected StandaloneHerder create(StandaloneConfig con2, String worker2, Plugins plu, ConnectorClientConfigOverridePolicy connector6, RestServer rest2, RestClient rest3) { OffsetBackingStore offset = new FileOffsetBackingStore(plu.newInternalConverter( true, JsonConverter.class.getName(), Map.of(JsonConverterConfig.SCHEMAS_ENABLE_CONFIG, "false"))); offset.configure(con2); Worker wor = new Worker(worker2, Time.SYSTEM, plu, con2, offset, connector6); return new StandaloneHerder(wor, con2.kafkaClusterId(), connector6); } @Override protected StandaloneConfig create2(Map<String, String> worker) { return new StandaloneConfig(worker); } public static void mai(String[] arg2) { ConnectStandalone connect = new ConnectStandalone(arg2); connect.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.8378.039−276.475
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.728−7.092

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

Score0.553

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.143.988−2.434
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.161.959+1.854
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.143.11+1.505
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.078+0.185

Intercept 0.07 + feature contributions = -2.253 (log-odds).
Score = sigmoid(-2.253) = 0.095.

Score0.119
Score50
Run 1

The code suffers from several readability issues. Variable names like 'connector2', 'connector3', 'connector4', 'connector5', 'connector6', 'create2', 'con', 'con2', 'wor', 'plu', 'rest2', 'rest3', 'arg2', and 'mai' are non-descriptive and confusing. The parse method is lengthy and mixes multiple parsing strategies with exception handling, making it hard to follow. The process method catches Throwable, which is overly broad. There are redundant code blocks for checking NAME_CONFIG presence. The structure and naming fail to convey intent clearly, leading to low readability despite some logical organization and flat nesting.

Run 2

The code is difficult to read due to poor naming conventions (connector2, file2, connector3, create2, etc.) that obscure intent. It contains deeply nested try-catch blocks, inconsistent method names (usa, create2, mai), and multiple actions packed into single lines. The parse method is overly long and mixes concerns: JSON parsing, validation, and fallback logic all in one place with cryptic variable names. Reading flow is disorganized—variable names like 'object' for an ObjectMapper and 'connector3' for a File are misleading. While the class-level Javadoc is decent, method-level documentation is sparse and the code structure lacks logical separation of parsing strategies. Error handling with broad Throwable catches adds to the ambiguity. Overall, the code requires significant effort to understand and maintain.

Run 3

The code has logical organization with a clear class structure and separated methods, but it suffers from poor variable naming (e.g., 'connector2', 'file2', 'con2', 'worker2', 'plu', 'rest2', 'rest3', 'connector3', 'connector4', 'connector5', 'connector6', 'arg2', 'wor', 'create2') that obscures intent. The method names are also confusing—'usa()' appears to be a typo for 'usage()' and 'mai()' for 'main()'—which severely hampers clarity. Nesting is moderate, and the parse() method is long and does multiple things across several try-catch blocks, reducing readability. Action granularity is reasonable in most places but the long method chains and multi-line throws add complexity. The reading flow is disrupted by these naming and structural issues.

Run 1

Code Structure: Responsibilities are separated into methods, and parsing follows a documented fallback sequence, though validation is duplicated. Nesting: Mostly shallow, with moderate nesting in the callback and connector-name validation. Clarity of intent: Documentation and API calls explain the overall purpose, but abbreviated and numbered identifiers such as con2, connector4, create2, usa, and mai obscure meaning. Code length: Reasonably concise, although repeated validation and exception-handling blocks add verbosity. Action granularity: Generally one action per statement; chained calls and inline object construction occasionally increase cognitive load. Reading flow: Startup, parsing, and worker creation are logically organized, but inconsistent indentation, dense imports, and weak naming interrupt otherwise natural flow.

Run 2

Code Structure: Methods separate connector processing, configuration parsing, and runtime construction logically. Nesting: Mostly shallow, though the callback and nested name-validation conditions add complexity. Clarity of intent: Documentation and API calls explain the purpose, but abbreviated or numbered identifiers such as usa, mai, con2, connector4, and create2 obscure meaning; the parse Javadoc also names a nonexistent parameter. Code length: Reasonably compact, although mandatory-name validation is duplicated and imports are visually dense. Action granularity: Generally one action per statement, with a few chained calls and inline constructions requiring extra attention. Reading flow: The documented JSON-to-properties fallback sequence is easy to follow, but exception-driven parsing, inconsistent naming, omitted conditional braces, and uneven formatting interrupt the flow.

Run 3

Code Structure: Methods separate connector processing, configuration parsing, and runtime construction logically, though parsing combines three fallback formats. Nesting: Generally moderate, with a loop containing a callback and a nested conditional in parsing; neither is excessively deep. Clarity of intent: Documentation and Kafka API calls explain the purpose, but names such as usa, mai, con2, connector4, and wor obscure roles. The parse documentation also references a parameter name absent from the signature. Code length: Reasonably concise, although repeated name validation and lengthy exception messages add bulk. Action granularity: Most statements perform one action, with a few compound expressions that require extra interpretation. Reading flow: Sequential parsing attempts and straightforward setup provide a natural progression, but inconsistent naming, tightly packed imports, uneven line wrapping, and unbraced conditionals reduce readability.