Sample

int-23d2ef4aa485-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines108

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5020–1; higher is more readable
Dorn0.2850–1; higher is more readable
Mi0.570–1; higher is more readable
LLOC36Logical lines; fewer is more readable
DeepSeek V4 Pro8.330–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.4130–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 (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); } } else { if (logger.isDebugEnabled()) { logger.debug(request.getMethod() + " " + request.getURI()); } sockJsSession.handleInitialRequest(request, response, getFrameFormat(request)); } } 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)))) {} else { 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.5096.387−168.181
Source linesThe number of non-empty source lines.108+43.2
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.102−7.652

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

Score0.502

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.109−2.823
Indentation frequencyHow rapidly indentation changes from line to line.98+2.653
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.98−1.828
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.972−1.162
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.107.957+1.099
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.114+1.035
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.093+0.038

Intercept 0.07 + feature contributions = -0.918 (log-odds).
Score = sigmoid(-0.918) = 0.285.

Score0.57
Score36
Run 1

The code has severe readability issues. The handleRequestInternal method contains deeply nested conditional logic (3 levels), with multiple actions crammed into single if-else blocks, violating action granularity principles. The condition `if (!((sockJsSession.isNew())))` uses confusing double negatives and unnecessary parentheses, obscuring intent. The getCallbackParam method contains a useless empty if-else block (`if (!((!StringUtils.hasLength(value)))) {} else { return null; }`) that should be inverted and simplified. Comments reference external issues without context. While the class structure follows Spring conventions and imports are organized, the method-level code structure is tangled and hard to follow. The nesting depth forces readers to track multiple branches simultaneously, and the mixture of logging statements within conditional blocks disrupts reading flow. This code would benefit from early returns, method extraction, and elimination of redundant boolean expressions.

Run 2

The code has several readability issues. The most severe is in 'handleRequestInternal', where nested if-else blocks with multiple actions per line create a tangled, hard-to-follow structure. This violates the guidelines for nesting, action granularity, and reading flow. The method mixes bracket styles and places multiple statements on single lines, making the logical flow difficult to trace. Similarly, 'getCallbackParam' uses an awkward empty if block and a redundant else clause, obscuring intent. While imports are organized, class structure is logical, and logging adds clarity, these positives are offset by unnecessary verbosity in some areas and the convoluted conditional logic. The code demonstrates average structure but poor execution in control flow and formatting.

Run 3

The code has some clear structure with logical method separation, but several readability issues exist. The handleRequestInternal method has deeply nested conditional logic (3-4 levels), making it hard to follow the flow. Lines 54-69 contain multiple actions and nested if-else statements that could be flattened or extracted. The getCallbackParam method has an awkward empty if block with an else clause (lines 83-85) that is confusing and should be inverted. The logic is sound but the nesting and unnatural conditional structures impede readability. The code has good naming conventions and appropriate use of abstract methods, but the conditional complexity and some redundant parentheses (like `!((sockJsSession.isNew()))`) reduce clarity. The method lengths are reasonable, but the nested conditionals in handleRequestInternal would benefit from early returns or guard clauses to improve the reading flow. Overall, it's maintainable but requires careful reading to understand the control flow.

Run 1

Code Structure: Responsibilities are sensibly divided into request handling, frame writing, and callback parsing, but malformed-looking conditional formatting obscures organization. Nesting: Request handling has several nested branches and logging checks; redundant parentheses and compressed braces make the hierarchy harder to follow. Clarity of intent: Descriptive method names and types communicate purpose, but double negation and an empty conditional branch in callback validation needlessly obscure simple logic. Code length: Generally compact, though redundant syntax and commented-out code add noise. Action granularity: Most statements occupy separate lines, but multiple conditionals and closing braces share lines in key control-flow sections. Reading flow: Imports, documentation, and method boundaries are conventional; inconsistent indentation and inverted conditions interrupt otherwise natural top-to-bottom reading.

Run 2

Code Structure: Responsibilities are sensibly separated into request handling, frame writing, and callback parsing, but awkward conditional formatting obscures the main handler. Nesting: Session-state branches and logging checks create moderate nesting, worsened by compressed braces. Clarity of intent: Descriptive names and framework types explain most operations; redundant parentheses, double negation, and an empty conditional branch make simple checks confusing. Code length: Generally concise, though obsolete commented-out code and unnecessarily complex conditions add clutter. Action granularity: Most statements occupy separate lines, but combined conditional openings and closing braces undermine this consistency. Reading flow: Method organization is natural, while the inverted new-session check and poorly formatted branches interrupt straightforward top-to-bottom reading.

Run 3

Code Structure: Sensible separation of request handling, frame writing, and callback validation, but the central branching is awkwardly formatted. Nesting: Session-state checks and logging introduce moderate nesting, worsened by inline braces. Clarity of intent: Descriptive method names and types help, but redundant parentheses, negation, and an empty conditional branch obscure otherwise simple checks. Code length: Generally compact, though commented-out code and unnecessarily complex conditions add noise. Action granularity: Most lines express one action, but multiple conditional statements and closing/opening braces share lines in the request handler. Reading flow: Helper methods and consistent naming support navigation, while inverted conditions and inconsistent formatting interrupt the flow.