Sample

int-2d72717f229e-I13

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

Matched original source

Lines109

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5090–1; higher is more readable
Dorn0.2890–1; higher is more readable
Mi0.570–1; higher is more readable
LLOC36Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.4280–1; higher is more readable

Views

Source code

package org.springframework.web.socket.sockjs.transport.handler; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.regex.Pattern; import org.jspecify.annotations.Nullable; import org.springframework.http.MediaType; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.sockjs.SockJsException; import org.springframework.web.socket.sockjs.frame.SockJsFrame; import org.springframework.web.socket.sockjs.frame.SockJsFrameFormat; import org.springframework.web.socket.sockjs.transport.SockJsSession; import org.springframework.web.socket.sockjs.transport.SockJsSessionFactory; import org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession; import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriUtils; /** * Base class for HTTP transport handlers that push messages to connected clients. * * @author Rossen Stoyanchev * @since 4.0 */ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransportHandler implements SockJsSessionFactory { /** * Pattern for validating callback parameter values. */ private static final Pattern CALLBACK_PARAM_PATTERN = Pattern.compile("[0-9A-Za-z_.]*"); @Override public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException { AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession; // https://github.com/sockjs/sockjs-client/issues/130 // sockJsSession.setAcceptedProtocol(protocol); // Set content type before writing response.getHeaders().setContentType(getContentType()); handleRequestInternal(request, response, sockJsSession); } protected void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, AbstractHttpSockJsSession sockJsSession) throws SockJsException { if (sockJsSession.isNew()) { if (logger.isDebugEnabled()) { logger.debug(request.getMethod() + " " + request.getURI()); } sockJsSession.handleInitialRequest(request, response, getFrameFormat(request)); } else if (sockJsSession.isClosed()) { if (logger.isDebugEnabled()) { logger.debug("Connection already closed (but not removed yet) for " + sockJsSession); } writeFrame(SockJsFrame.closeFrameGoAway(), request, response, sockJsSession); } else if (!sockJsSession.isActive()) { if (logger.isTraceEnabled()) { logger.trace("Starting " + getTransportType() + " async request."); } sockJsSession.handleSuccessiveRequest(request, response, getFrameFormat(request)); } else { if (logger.isDebugEnabled()) { logger.debug("Another " + getTransportType() + " connection still open for " + sockJsSession); } writeFrame(SockJsFrame.closeFrameAnotherConnectionOpen(), request, response, sockJsSession); } } private void writeFrame(SockJsFrame frame, ServerHttpRequest request, ServerHttpResponse response, AbstractHttpSockJsSession sockJsSession) { String formattedFrame = getFrameFormat(request).format(frame); try { response.getBody().write(formattedFrame.getBytes(SockJsFrame.CHARSET)); } catch (IOException ex) { throw new SockJsException("Failed to send " + formattedFrame, sockJsSession.getId(), ex); } } protected abstract MediaType getContentType(); protected abstract SockJsFrameFormat getFrameFormat(ServerHttpRequest request); protected final @Nullable String getCallbackParam(ServerHttpRequest request) { String query = request.getURI().getQuery(); MultiValueMap<String, String> params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams(); String value = params.getFirst("c"); if (!StringUtils.hasLength(value)) { return null; } String result = UriUtils.decode(value, StandardCharsets.UTF_8); return (CALLBACK_PARAM_PATTERN.matcher(result).matches() ? result : null); } }

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.4989.917−164.667
Source linesThe number of non-empty source lines.109+43.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.097−7.645

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

Score0.509

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.110−2.858
Indentation frequencyHow rapidly indentation changes from line to line.99+2.687
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.99−1.851
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.113.936−1.161
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.108.93+1.113
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.113.991+1.035
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.09+0.067

Intercept 0.07 + feature contributions = -0.898 (log-odds).
Score = sigmoid(-0.898) = 0.289.

Score0.57
Score36
Run 1

The code is well-structured with clear separation of concerns: request handling, frame writing, and callback parameter validation are split into focused methods. Nesting is minimal—only one level of conditionals in handleRequestInternal, with debug logging kept short. Intent is explicit through descriptive method names and clear branching logic. Logging statements slightly lengthen the code but aid maintainability. Action granularity is mostly one action per line, though some method signatures and the getCallbackParam chain are multi-step. Reading flow follows a logical sequence from public handler to private helpers. Minor deductions: repeated logging blocks could be extracted, and getCallbackParam's query parsing is somewhat dense. Overall, highly readable with strong structure and clarity.

Run 2

The code is well-structured and highly readable. It follows a logical organization with clear separation of concerns: request handling, frame writing, and parameter validation. Nesting is minimal, primarily limited to if-else chains in the request handling method, which is appropriate for the branching logic. The intent of each method is evident from its name and documentation. Code length is concise, avoiding unnecessary boilerplate. Action granularity is mostly one action per line, enhancing readability. However, the `getCallbackParam` method chains several operations in a single expression, slightly reducing clarity. The reading flow is natural, with methods arranged in a logical order. Overall, the code demonstrates good practices such as early returns, clear naming, and appropriate use of abstraction, making it maintainable and easy to understand.

Run 3

The code is well-structured and readable. It follows a clear logical organization with a base class handling HTTP transport, uses proper Java naming conventions, and includes helpful Javadoc. Methods are concise and focused, with minimal nesting (only one level deep in conditionals). Intent is clear throughout, especially in method names like handleInitialRequest and handleSuccessiveRequest. Action granularity is good—most lines perform a single logical operation. Reading flow is natural: handleRequest delegates to handleRequestInternal, which branches cleanly, and helper methods like writeFrame and getCallbackParam are separated appropriately. Minor downsides: the callback parameter validation in getCallbackParam is somewhat dense, and the commented-out code for setAcceptedProtocol could be removed for cleanliness. Overall, the code demonstrates solid readability with only small areas for improvement.

Run 1

Code Structure: Well-organized methods separate request dispatch, frame writing, and callback validation, with clear extension points. Nesting: Shallow overall; logging checks add only one level within the session-state branches. Clarity of intent: Descriptive method and variable names make behavior clear, though the terse callback key "c" and commented-out protocol code require context. Code length: Concise for its responsibilities, with minor repetition in logging guards. Action granularity: Statements generally perform one action each, although the query-parsing chain combines several transformations on one line. Reading flow: Request handling follows a natural sequence, and session states are handled systematically. Long signatures and the query-parsing line slightly interrupt scanning, but consistent formatting and focused helper methods maintain strong readability.

Run 2

Code Structure: Well-organized methods separate request dispatch, frame writing, callback validation, and subclass customization. Nesting: Shallow overall; logging checks add only one level inside the session-state branches. Clarity of intent: Descriptive method names, explicit session-state checks, and focused comments make behavior clear, though the callback key "c" and commented-out protocol code introduce minor ambiguity. Code length: Appropriately concise, with slight repetition in logging guards and frame-format retrieval. Action granularity: Most statements perform one clear action; the query-parsing chain combines several operations but remains understandable. Reading flow: Request setup leads naturally into state handling and supporting methods. Consistent formatting supports scanning, although the dense import block and obsolete commented-out code add minor visual noise.

Run 3

Code Structure: Well-organized methods separate request dispatch, frame writing, callback parsing, and subclass extension points. Nesting: Shallow overall; logging guards add only one level within the session-state branches. Clarity of intent: Descriptive names, explicit session-state checks, and focused documentation make the purpose clear, though the callback key "c" and obsolete commented-out code introduce minor ambiguity. Code length: Concise for its responsibilities, with some repetitive logging boilerplate and a long callback-parsing expression. Action granularity: Most lines perform one clear action; chained URI parsing combines several operations but remains understandable. Reading flow: Request handling proceeds naturally from setup to state-specific behavior, followed by helpers and extension points. Consistent formatting supports scanning, although ungrouped imports and excess blank lines slightly reduce polish.