Sample

int-5cad0de03703-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines164

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5450–1; higher is more readable
Dorn0.0920–1; higher is more readable
Mi0.1190–1; higher is more readable
LLOC52Logical lines; fewer is more readable
DeepSeek V4 Pro160–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.3730–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(); final int a = 1; final int b = 2; Exit.exit((a + b)); } } /** * 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.8498.912−280.464
Source linesThe number of non-empty source lines.164+65.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.725−7.087

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

Score0.545

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.165−4.806
Indentation frequencyHow rapidly indentation changes from line to line.141+4.14
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.141−2.815
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.976−2.56
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.163.98+1.882
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.146.073+1.552
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.072+0.241

Intercept 0.07 + feature contributions = -2.295 (log-odds).
Score = sigmoid(-2.295) = 0.092.

Score0.119
Score52
Run 1

The code is generally readable, with clear class and method names and good use of logging. The parsing method is logically structured and handles multiple formats sequentially. However, there are some issues: the 'processExtraArgs' method has an odd error-handling block with 'final int a = 1; final int b = 2; Exit.exit((a + b));' which is confusing and unnecessary. The 'createHerder' method has a very long line for instantiating FileOffsetBackingStore, reducing readability. The use of raw type in 'new TypeReference<>() { }' is acceptable but could be clearer. The main method is short and clear. Overall, the code is well-organized but has a few minor clarity and length issues. Readability score is above average.

Run 2

The code is generally well-structured and readable, with clear method separation and javadoc comments explaining the parsing logic. The `processExtraArgs` method has moderate nesting and a suspicious 'dead code' sequence (a=1, b=2, Exit.exit(a+b)) that hurts clarity and intent. The `parseConnectorConfigurationFile` method is well-documented and follows a logical fallback sequence, though it is somewhat long. Most actions are on separate lines, and the reading flow is natural. Overall, it demonstrates good organization but is slightly marred by the unexplained exit logic and method length.

Run 3

The code is generally well-structured, with clear class hierarchy and method separation. Imports are organized, and Javadoc helps explain the complex parsing logic. However, readability issues exist in specific areas: the `processExtraArgs` method uses a lambda with one-line if/else branches, and contains the suspicious hardcoded exit value `Exit.exit((a + b))` with unnecessary local variables. The `parseConnectorConfigurationFile` method has three try-catch blocks with fallback parsing logic and empty catch bodies that log debug messages, which somewhat obscures intent. The method signature of `createHerder` is quite long. Some lines like the `new FileOffsetBackingStore` constructor call are verbose. The empty diamond operator `new TypeReference<>() { }` appears twice. Overall, the code demonstrates competent Java practices with descriptive names and logical flow, but could be improved by extracting methods, simplifying error handling, and removing the redundant exit code.

Run 1

Code Structure: Well-separated methods organize CLI handling, configuration parsing, and runtime construction; parsing repeats mandatory-name validation. Nesting: Mostly shallow, with moderate nesting in the connector callback and request-name validation. Clarity of intent: Descriptive method and variable names plus detailed documentation make the purpose clear, but 'cb' and the arbitrary 'a + b' exit-code calculation obscure intent. Code length: Generally proportionate to functionality, although repeated validation and unnecessary exit-code variables add clutter. Action granularity: Most statements perform one action; chained calls and nested constructor expressions slightly increase reading effort. Reading flow: Startup and documented parsing fallbacks follow a natural sequence. Exception-driven fallback parsing requires some mental tracking, while inconsistent continuation indentation, unbraced conditionals, and densely grouped imports reduce visual readability.

Run 2

Code Structure: Well-separated methods organize CLI handling, configuration parsing, and runtime construction, though parsing repeats validation logic. Nesting: Mostly shallow, with moderate nesting in the callback and connector-name validation. Clarity of intent: Descriptive method names, variables, and documentation explain the purpose and parsing order; however, the arbitrary a/b variables and computed exit code obscure intent. Code length: Generally proportionate to functionality, but repeated missing-name checks and verbose expressions could be simplified. Action granularity: Most statements perform one action, although chained calls and nested constructor expressions increase cognitive load. Reading flow: The documented JSON-to-properties fallback is easy to follow, but exception-driven parsing, uneven continuation indentation, ungrouped imports, and omitted braces slightly disrupt readability.

Run 3

Code Structure: Responsibilities are separated into focused methods, with a clearly documented parsing sequence; repeated name validation could be extracted. Nesting: Mostly shallow, although the callback and nested connector-name checks add some complexity. Clarity of intent: Descriptive method and variable names, Javadoc, and logging explain the workflow well. However, arbitrary variables a and b obscure the exit status, and cb is less descriptive. Code length: Generally appropriate, but duplicated validation and verbose generic declarations introduce minor overhead. Action granularity: Most statements perform one action; chained calls and configuration mutations remain manageable. Reading flow: Startup, connector creation, parsing fallbacks, and worker construction follow logical sequences. Dense imports, inconsistent continuation indentation, omitted conditional braces, and exception-driven parsing slightly interrupt readability.