Sample

int-9ab9ef5c7e5f-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines109

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5180–1; higher is more readable
Dorn0.2870–1; higher is more readable
Mi0.570–1; higher is more readable
LLOC35Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.4240–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 { // https://github.com/sockjs/sockjs-client/issues/130 // sockJsSession.setAcceptedProtocol(protocol); // Set content type before writing response.getHeaders().setContentType(getContentType()); handleRequestInternal(request, response, ((AbstractHttpSockJsSession) wsSession)); } 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.4968.622−163.965
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.1−7.651

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

Score0.518

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.945−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.091+0.055

Intercept 0.07 + feature contributions = -0.911 (log-odds).
Score = sigmoid(-0.911) = 0.287.

Score0.57
Score35
Run 1

The code is generally well-structured with clear class hierarchy, method separation, and JavaDoc. Methods are focused and each does a single task, with no deeply nested logic. The reading flow is logical, starting with request handling and moving to internal logic. However, readability is reduced by excessive debug logging blocks that interrupt the main logic flow, especially in handleRequestInternal. The commented-out lines and blank line in handleRequest add minor clutter. While the code is concise and follows clean coding principles, the repeated logger checks make the control flow harder to follow at a glance. Variable names are descriptive, and imports are organized. Action granularity is mostly one action per line. Overall, it's readable but could be improved by extracting logging or using more concise logging patterns.

Run 2

The code is well-structured, with clear separation of concerns: request handling, session state logic, frame writing, and utility methods. The main handleRequestInternal method uses a flat if-else chain with minimal nesting, making the session-state logic easy to follow. Each branch performs a single clear action (handling initial request, writing a close frame, etc.). Method names and logging statements clearly convey intent. The getCallbackParam method is appropriately concise and readable, with a logical validation flow. Minor deductions: a stray blank comment block in handleRequest and slight verbosity from repeated logger checks. Overall, the code demonstrates strong readability with clear boundaries and predictable flow.

Run 3

The code is generally well-structured and readable. It uses clear method names, follows Spring conventions, and has good separation of concerns. The handleRequestInternal method uses if-else branching with minimal nesting, though each branch contains a logging check that adds slight repetition. The writeFrame method is concise and single-purpose. However, there are a few issues: an unused commented-out line in handleRequest adds confusion, the getCallbackParam method chains multiple operations in a single expression making it harder to follow, and there's a blank line artifact that appears accidental. The code could benefit from extracting the logging pattern or simplifying the callback parameter parsing. Overall, the class has clear intent and maintains good readability, but minor improvements would enhance clarity.

Run 1

Code Structure: Well-organized methods separate request dispatch, session-state handling, frame writing, and callback validation. Nesting: Mostly shallow, with logging checks adding only one level inside the state branches. Clarity of intent: Descriptive names and explicit session-state checks communicate purpose, though the unexplained session cast, callback key "c", and obsolete commented-out code reduce clarity. Code length: Appropriately concise overall, with minor clutter from repeated logging guards and excess blank lines. Action granularity: Most statements perform one clear action; chained query parsing and inline frame conversion are slightly denser. Reading flow: Request setup naturally leads into state handling and helper methods, but inconsistent whitespace and stale comments interrupt an otherwise coherent flow.

Run 2

Code Structure: Responsibilities are logically separated into request handling, frame writing, and callback validation, with clear abstract extension points. Nesting: The session-state conditional chain is straightforward; nested logging checks add only modest depth. Clarity of intent: Descriptive method names, explicit session-state checks, and focused comments make the purpose clear, although the abbreviated callback key and commented-out protocol code introduce minor ambiguity. Code length: Methods are concise and appropriately scoped, but redundant blank lines and obsolete commented code add clutter. Action granularity: Most lines perform one action; the query-parsing chain and decode-validation expression are somewhat dense but manageable. Reading flow: Execution proceeds naturally from response setup through state handling to helper methods. Consistent formatting supports scanning, though the unexplained session cast and unused handler parameter slightly interrupt comprehension.

Run 3

Code Structure: Well-organized methods separate request dispatch, session-state handling, frame writing, and callback validation. Nesting: Mostly shallow, with logging guards adding only one extra level within state branches. Clarity of intent: Descriptive method names and explicit session checks make behavior clear; the terse callback key and obsolete commented-out code slightly obscure intent. Code length: Appropriately concise overall, though repeated logging guards and excess blank lines add clutter. Action granularity: Statements generally perform one action per line; the chained query parsing expression is somewhat dense. Reading flow: Request handling progresses naturally into focused helpers and extension points, but inconsistent whitespace, ungrouped imports, and stale comments interrupt an otherwise readable flow.