Sample

int-83adbfbe20b6-I13

Lower every eligible classic and enhanced for loop to a while loop

Matched original source

Lines79

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5110–1; higher is more readable
Dorn0.3560–1; higher is more readable
Mi0.2810–1; higher is more readable
LLOC14Logical lines; fewer is more readable
DeepSeek V4 Pro180–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6180–1; higher is more readable

Views

Source code

package org.springframework.http.codec.json; import java.io.InputStreamReader; import java.util.Map; import com.google.gson.Gson; import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.codec.AbstractDataBufferDecoder; import org.springframework.core.codec.Decoder; import org.springframework.core.codec.DecodingException; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.MediaType; import org.springframework.util.Assert; import org.springframework.util.MimeType; /** * {@link Decoder} that reads a byte stream into JSON and converts it to Objects with * <a href="https://google.github.io/gson/">Google Gson</a>. * <p>{@code Flux<*>} target types are not available because non-blocking parsing is not supported, * so this decoder targets only {@code Mono<*>} types. Attempting to decode to a {@code Flux<*>} will * result in a {@link UnsupportedOperationException} being thrown at runtime. * * @author Brian Clozel * @since 7.0 */ public class GsonDecoder extends AbstractDataBufferDecoder<Object> { private static final MimeType[] DEFAULT_JSON_MIME_TYPES = new MimeType[] { MediaType.APPLICATION_JSON, new MediaType("application", "*+json"), }; private final Gson gson; /** * Construct a new decoder using a default {@link Gson} instance * and the {@code "application/json"} and {@code "application/*+json"} * MIME types. */ public GsonDecoder() { this(new Gson(), DEFAULT_JSON_MIME_TYPES); } /** * Construct a new decoder using the given {@link Gson} instance * and the provided MIME types. * @param gson the gson instance to use * @param mimeTypes the mime types the decoder should support */ public GsonDecoder(Gson gson, MimeType... mimeTypes) { super(mimeTypes); Assert.notNull(gson, "A Gson instance is required"); this.gson = gson; } @Override public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) { return super.canDecode(elementType, mimeType) && !CharSequence.class.isAssignableFrom(elementType.toClass()); } @Override public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { throw new UnsupportedOperationException("Stream decoding is currently not supported"); } @Override public @Nullable Object decode(DataBuffer buffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingException { try { return this.gson.fromJson(new InputStreamReader(buffer.asInputStream()), targetType.getType()); } finally { DataBufferUtils.release(buffer); } } }

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.2531.532−83.541
Source linesThe number of non-empty source lines.79+31.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.5.158−7.737

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

Score0.511

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.169.988−3.535
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.170+1.938
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.80−1.796
Indentation frequencyHow rapidly indentation changes from line to line.61+1.373
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.78.924+0.693
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.07+0.265

Intercept 0.07 + feature contributions = -0.593 (log-odds).
Score = sigmoid(-0.593) = 0.356.

Score0.281
Score14
Run 1

The code is well-structured and highly readable. It has a clear class hierarchy, logical organization with constructors and overridden methods, and minimal nesting. Each method has a single, clear purpose, and the actions are concise—one primary operation per line. The use of Javadoc comments and meaningful method names (e.g., canDecode, decode) enhances clarity of intent. The code length is appropriate, avoiding unnecessary verbosity while maintaining completeness. Reading flow is natural: the constructors lead to the overridden methods, each returning or throwing clear exceptions. Minor deductions include slightly long import statements and a single-line method that could be more readable if split, but overall the code is highly maintainable and understandable.

Run 2

The code is well-structured with clear class-level documentation, logical constructor overloads, and a minimal number of overridden methods. Nesting is shallow, with only a try-finally block in the decode method. The intent of each method is clear: canDecode validates type compatibility, decode(Publisher...) explicitly rejects streaming, and decode(DataBuffer...) performs the Gson conversion. The code is concise, with each method performing a single focused action. Action granularity is good—complex expressions are limited but readable. The reading flow is natural: constants, constructors, then overridden methods in a logical order. Minor deductions include the moderately long return statement in canDecode and the slightly compact expression in decode, but overall readability is high.

Run 3

The code is highly readable with a clear, logical structure. The class has a single responsibility, is well-documented, and follows common Spring patterns. Nesting is minimal, with no deep conditionals or loops. Intent is explicit through method names, Javadoc, and clear exception messages. The code is concise without sacrificing clarity, and actions are well-separated per line. The reading flow is natural: class declaration, fields, constructors, then overridden methods in order. Minor deductions include the line `return this.gson.fromJson(...)` being slightly long and combining multiple actions (stream creation, parsing, and return), and the `canDecode` method's boolean logic is slightly dense but still understandable. Overall, excellent readability.

Run 1

Code Structure: Logically organized into constants, state, constructors, and decoder overrides, with helpful documentation. Nesting: Minimal; the only nested control structure is a straightforward try/finally. Clarity of intent: Descriptive names and Javadoc clearly explain JSON decoding and the lack of streaming support. Code length: Concise implementation with proportionate documentation, though long method signatures reduce scanability. Action granularity: Statements generally perform one action per line; the nested reader construction within fromJson slightly compresses several operations. Reading flow: Natural progression from configuration to capability checks and decoding, with resource cleanup clearly visible. Minor formatting weaknesses include ungrouped imports, extra blank lines, and unwrapped signatures.

Run 2

Code Structure: Logical organization separates MIME constants, configuration, constructors, capability checks, and decoding methods. Nesting: Very shallow, with only a straightforward try/finally block. Clarity of intent: Descriptive names and documentation clearly explain Gson decoding, supported MIME types, and the streaming limitation. Code length: Concise implementation; constructor documentation adds useful context rather than unnecessary verbosity. Action granularity: Most statements perform one action, although reader creation, stream access, type resolution, and parsing are combined in one return expression. Reading flow: Natural progression from configuration to behavior, with explicit buffer cleanup. Long method signatures and the compact import section slightly reduce scanability.

Run 3

Code Structure: Constants, state, constructors, and overrides are logically organized with clear separation of responsibilities. Nesting: Minimal nesting; the only control structure is a straightforward try/finally. Clarity of intent: Descriptive names and useful documentation clearly explain JSON decoding and unsupported streaming behavior. Code length: Concise implementation with little unnecessary code; documentation is proportionate. Action granularity: Most lines perform one action, although the decoding return statement combines stream access, reader construction, and deserialization. Reading flow: Natural top-to-bottom progression and consistent formatting make the class easy to follow. Long method signatures and the compound canDecode expression slightly reduce scanability.