Sample

int-698667cb79e5-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines116

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6490–1; higher is more readable
Dorn0.6990–1; higher is more readable
Mi0.0970–1; higher is more readable
LLOC44Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.430–1; higher is more readable

Views

Source code

package org.apache.kafka.connect.converters; import org.apache.kafka.common.config.ConfigDef; import org.apache.kafka.common.errors.SerializationException; import org.apache.kafka.common.serialization.Deserializer; import org.apache.kafka.common.serialization.Serializer; import org.apache.kafka.common.utils.Utils; import org.apache.kafka.common.utils.internals.AppInfoParser; import org.apache.kafka.connect.data.Schema; import org.apache.kafka.connect.data.SchemaAndValue; import org.apache.kafka.connect.errors.DataException; import org.apache.kafka.connect.storage.Converter; import org.apache.kafka.connect.storage.ConverterType; import org.apache.kafka.connect.storage.HeaderConverter; import org.apache.kafka.connect.storage.StringConverterConfig; import java.util.HashMap; import java.util.Map; /** * {@link Converter} and {@link HeaderConverter} implementation that only supports serializing to and deserializing from number values. * It does support handling nulls. When converting from bytes to Kafka Connect format, the converter will always return the specified * schema. * <p> * This implementation currently does nothing with the topic names or header keys. */ abstract class NumberConverter<T extends Number> implements Converter, HeaderConverter { private final Serializer<T> serializer; private final Deserializer<T> deserializer; private final String typeName; private final Schema schema; /** * Create the converter. * * @param typeName the displayable name of the type; may not be null * @param schema the optional schema to be used for all deserialized forms; may not be null * @param serializer the serializer; may not be null * @param deserializer the deserializer; may not be null */ protected NumberConverter(String typeName, Schema schema, Serializer<T> serializer, Deserializer<T> deserializer) { this.typeName = typeName; this.schema = schema; this.serializer = serializer; this.deserializer = deserializer; assert this.serializer != null; assert this.deserializer != null; assert this.typeName != null; assert this.schema != null; } @Override public String version() { return AppInfoParser.getVersion(); } @Override public ConfigDef config() { return NumberConverterConfig.configDef(); } @Override public void configure(Map<String, ?> configs) { NumberConverterConfig conf = new NumberConverterConfig(configs); boolean isKey = conf.type() == ConverterType.KEY; serializer.configure(configs, isKey); deserializer.configure(configs, isKey); } @Override public void configure(Map<String, ?> configs, boolean isKey) { Map<String, Object> conf = new HashMap<>(configs); conf.put(StringConverterConfig.TYPE_CONFIG, isKey ? ConverterType.KEY.getName() : ConverterType.VALUE.getName()); configure(conf); } @SuppressWarnings("unchecked") protected T cast(Object value) { return (T) value; } @Override public byte[] fromConnectData(String topic, Schema schema, Object value) { try { return serializer.serialize(topic, value == null ? null : cast(value)); } catch (ClassCastException e) { throw new DataException("Failed to serialize to " + typeName + " (was " + value.getClass() + "): ", e); } catch (SerializationException e) { throw new DataException("Failed to serialize to " + typeName + ": ", e); } } @Override public SchemaAndValue toConnectData(String topic, byte[] value) { try { return new SchemaAndValue(schema, deserializer.deserialize(topic, value)); } catch (SerializationException e) { throw new DataException("Failed to deserialize " + typeName + ": ", e); } } @Override public byte[] fromConnectHeader(String topic, String headerKey, Schema schema, Object value) { return fromConnectData(topic, schema, value); } @Override public SchemaAndValue toConnectHeader(String topic, String headerKey, byte[] value) { return toConnectData(topic, value); } @Override public void close() { Utils.closeQuietly(this.serializer, "number converter serializer"); Utils.closeQuietly(this.deserializer, "number converter deserializer"); } }

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.4869.167−160.682
Source linesThe number of non-empty source lines.116+46.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.754−7.131

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

Score0.649

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.117−3.106
Indentation frequencyHow rapidly indentation changes from line to line.103+2.826
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.134.94−2.05
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.133.803+1.354
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.115.912+1.21
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.083+0.14

Intercept 0.07 + feature contributions = 0.842 (log-odds).
Score = sigmoid(0.842) = 0.699.

Score0.097
Score44
Run 1

The code is highly readable with a clear, logical structure. The class hierarchy and field declarations are well-organized, and method implementations are concise. Nesting is minimal—only conditional/ternary and try-catch blocks are used. Intent is clear from descriptive method/field names and Javadoc. Action granularity is excellent: most operations take one line, except for concise one-liners in `configure` and `fromConnectData` that still remain readable. Reading flow is natural, with methods grouped by interface responsibilities. Minor deductions: the `cast` method suppresses a warning and has a potentially confusing generic T parameter; the `configure` method has a blank line before the closing brace; and the constructor uses assertions instead of explicit argument validation, which slightly obscures runtime intent.

Run 2

The code is highly readable. Structure is logical with clear separation of concerns: fields, constructor, configuration methods, conversion methods, and lifecycle. Nesting is minimal—try/catch blocks are flat and focused. Intent is obvious from descriptive method and variable names, and the class-level Javadoc explains purpose well. Code is concise without unnecessary verbosity, though the blank line in `configure` before the closing brace is a minor inconsistency. Action granularity is good, with one logical operation per line. Reading flow is natural: constructor validates inputs via asserts, configuration delegates to serializers, and error handling wraps specific exceptions into Connect-specific exceptions with useful context. Minor deductions: the blank line inside `configure` and the use of `assert` for constructor validation instead of explicit checks slightly reduce consistency and robustness.

Run 3

The code is well-structured and readable. It follows a logical class organization with clear field declarations and a clean constructor. Nesting is minimal, and each method has a single, understandable purpose. Most lines perform one action, enhancing clarity. The method names and JavaDoc comments clearly convey intent. However, minor deductions are applied due to redundant null checks via assertions in the constructor (which are not active in production) and slight verbosity in exception handling. Overall, the code is easy to follow and maintain.

Run 1

Code Structure: Fields, initialization, configuration, conversion, and cleanup are logically organized into focused methods. Nesting: Minimal nesting, limited to straightforward try/catch blocks. Clarity of intent: Descriptive names, interface overrides, and documentation clearly convey the numeric converter's purpose; the unchecked cast and StringConverterConfig reference introduce minor ambiguity. Code length: Concise overall, with header methods appropriately delegating rather than duplicating conversion logic. Action granularity: Statements generally perform one action per line, although serialization combines null handling, casting, and delegation in one expression. Reading flow: Consistent formatting and predictable method organization make the code easy to follow; a missing blank line between methods, an extra blank line in configure, and several long lines slightly reduce polish.

Run 2

Code Structure: Well-organized fields, constructor, configuration, conversion, and cleanup methods; header conversion delegates cleanly to existing methods. Nesting: Shallow try/catch blocks and no complex nested control flow. Clarity of intent: Descriptive names, documentation, and contextual exception messages make the purpose clear, though the unchecked generic cast and use of StringConverterConfig in a number converter require extra interpretation. Code length: Concise, focused methods avoid unnecessary repetition. Action granularity: Generally one action per line; inline casting and conditional expressions remain manageable. Reading flow: Methods follow a natural lifecycle, with minor formatting inconsistencies such as missing blank lines between declarations and an extra blank line in configure.

Run 3

Code Structure: Well-organized class with focused methods and clear separation of configuration, conversion, and cleanup. Nesting: Shallow; straightforward try/catch blocks and simple conditional expressions are easy to follow. Clarity of intent: Descriptive names, interface overrides, and documentation explain the converter's purpose. The unchecked cast and use of StringConverterConfig within a number converter slightly reduce clarity. Code length: Concise, with header conversion delegating to existing methods rather than duplicating logic. Action granularity: Generally one action per line; serialization and error construction contain modestly dense expressions. Reading flow: Natural progression from initialization through configuration and conversion to cleanup. Minor formatting inconsistencies, including missing spacing between methods and an extra blank line, slightly interrupt an otherwise clean presentation.