Sample

int-9a1ef64e65b9-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines156

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.7440–1; higher is more readable
Dorn0.2270–1; higher is more readable
Mi0.5890–1; higher is more readable
LLOC53Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.3370–1; higher is more readable

Views

Source code

package org.springframework.mock.web; import java.io.IOException; import java.util.ArrayList; import java.util.List; import jakarta.servlet.AsyncContext; import jakarta.servlet.AsyncEvent; import jakarta.servlet.AsyncListener; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.util.Assert; import org.springframework.web.util.WebUtils; /** * Mock implementation of the {@link AsyncContext} interface. * * @author Rossen Stoyanchev * @since 3.2 */ public class MockAsyncContext implements AsyncContext { private final HttpServletRequest request; private final @Nullable HttpServletResponse response; private final List<AsyncListener> listeners = new ArrayList<>(); private @Nullable String dispatchedPath; private long timeout = 0xa * 0x3e8L; private final List<Runnable> dispatchHandlers = new ArrayList<>(); public MockAsyncContext(ServletRequest request, @Nullable ServletResponse response) { this.request = (HttpServletRequest) request; this.response = (HttpServletResponse) response; } public void addDispatchHandler(Runnable handler) { Assert.notNull(handler, "Dispatch handler must not be null"); synchronized (this) { if (this.dispatchedPath == null) { this.dispatchHandlers.add(handler); } else { handler.run(); } } } @Override public ServletRequest getRequest() { return this.request; } @Override public @Nullable ServletResponse getResponse() { return this.response; } @Override public boolean hasOriginalRequestAndResponse() { return (this.request instanceof MockHttpServletRequest && this.response instanceof MockHttpServletResponse); } @Override public void dispatch() { dispatch(this.request.getRequestURI()); } @Override public void dispatch(String path) { dispatch(null, path); } @Override public void dispatch(@Nullable ServletContext context, String path) { synchronized (this) { this.dispatchedPath = path; this.dispatchHandlers.forEach(Runnable::run); } } public @Nullable String getDispatchedPath() { return this.dispatchedPath; } @Override public void complete() { MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(this.request, MockHttpServletRequest.class); if (mockRequest != null) { mockRequest.setAsyncStarted(false); } for (AsyncListener listener : this.listeners) { try { listener.onComplete(new AsyncEvent(this, this.request, this.response)); } catch (IOException ex) { throw new IllegalStateException("AsyncListener failure", ex); } } } @Override public void start(Runnable runnable) { runnable.run(); } @Override public void addListener(AsyncListener listener) { this.listeners.add(listener); } @Override public void addListener(AsyncListener listener, ServletRequest request, ServletResponse response) { this.listeners.add(listener); } public List<AsyncListener> getListeners() { return this.listeners; } @Override public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException { return BeanUtils.instantiateClass(clazz); } /** * By default this is set to 10000 (10 seconds) even though the Servlet API * specifies a default async request timeout of 30 seconds. Keep in mind the * timeout could further be impacted by global configuration through the MVC * Java config or the XML namespace, as well as be overridden per request on * {@link org.springframework.web.context.request.async.DeferredResult DeferredResult} * or on * {@link org.springframework.web.servlet.mvc.method.annotation.SseEmitter SseEmitter}. * @param timeout the timeout value to use. * @see AsyncContext#setTimeout(long) */ @Override public void setTimeout(long timeout) { this.timeout = timeout; } @Override public long getTimeout() { return this.timeout; } }

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.4385.876−144.734
Source linesThe number of non-empty source lines.156+62.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.5.008−7.513

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

Score0.744

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.157−4.523
Indentation frequencyHow rapidly indentation changes from line to line.141+4.14
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.141−2.815
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.155.928+1.77
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.109.968−0.993
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.109.955+0.97
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.081+0.152

Intercept 0.07 + feature contributions = -1.228 (log-odds).
Score = sigmoid(-1.228) = 0.227.

Score0.589
Score53
Run 1

The code is well-structured, with clear separation of methods and a single responsibility for each. The nesting level is minimal, with only a couple of synchronized blocks and simple conditionals. Intent is mostly clear, although the purpose of `dispatchHandlers` and the behavior in `addDispatchHandler` requires some domain knowledge. The code is appropriately concise for a mock implementation. Action granularity is good: each line generally performs one logical step, and method bodies are short. The use of `0xa * 0x3e8L` for the timeout is slightly obscure and hurts readability; a numeric literal or named constant would be clearer. The `start(Runnable)` method is trivial but expected for the interface. Overall, the code follows conventional Java structure and is easy to follow with a natural top-down flow.

Run 2

The code is well-structured with clear separation of concerns and consistent formatting. It follows standard Java conventions with proper package organization, logical method ordering, and clear field declarations. The nesting is minimal - only one level in the synchronized blocks and loops, maintaining flat, readable code. Each method has a single, clear purpose with descriptive names that convey intent well. The code is concise without being cryptic, though a few methods like addListener are trivially short. Action granularity is good - most lines perform single operations, though the complete() method could be slightly more decomposed. Reading flow is natural and progressive, with methods arranged logically. Minor deductions: the timeout initialization using hex (0xa * 0x3e8L) is slightly obscure compared to direct literal, and the dispatch(String) method's null context parameter could use a brief comment. Overall, this is exemplary Spring framework code that balances clarity with functionality effectively.

Run 3

The code is highly readable with clear structure and purpose. Each method serves a single responsibility, and the class is logically organized with fields, constructors, and methods grouped coherently. Nesting is minimal, with only one synchronized block and one conditional, keeping the flow flat. Action granularity is appropriate—most lines perform one operation, though the conditional in addDispatchHandler could be slightly clearer. Intent is explicit thanks to descriptive method names and a helpful Javadoc explaining the non-standard timeout default. Length is concise, avoiding unnecessary verbosity. Reading flow is natural, progressing from simple getters to more complex dispatch and listener logic. Minor deductions: the magic number `0xa * 0x3e8L` obscures the timeout value, and methods like addListener overloads simply ignore parameters without explanation, which could confuse readers.

Run 1

Code Structure: Well-organized fields, constructor, and small interface methods keep responsibilities distinct. Nesting: Mostly flat, with limited nesting in synchronization blocks and listener exception handling. Clarity of intent: Descriptive names, annotations, and documentation make the mock behavior clear; however, the hexadecimal timeout expression obscures a simple value, and ignored parameters are unexplained. Code length: Concise overall, with appropriate delegation and minimal duplication; the timeout documentation is somewhat lengthy. Action granularity: Statements generally perform one action per line, and the method reference clearly expresses handler execution. Reading flow: Consistent formatting and straightforward method implementations support natural reading, although imports lack grouping whitespace and field ordering could better group dispatch-related state.

Run 2

Code Structure: Well organized into fields, construction, dispatch operations, lifecycle methods, listener management, and timeout accessors. Nesting: Mostly flat, with modest nesting in synchronized dispatch handling and listener exception handling. Clarity of intent: Descriptive names, interface overrides, and documentation make the mock's purpose clear; the hexadecimal timeout expression unnecessarily obscures a simple default value, and ignored parameters lack explanation. Code length: Methods are concise and focused, though the timeout documentation is comparatively lengthy. Action granularity: Statements generally perform one action per line, with clear separation of validation, state changes, and callbacks. Reading flow: Consistent formatting and straightforward delegation support natural reading; closely related operations are mostly grouped, although dispatchHandlers could sit alongside the other dispatch-related field.

Run 3

Code Structure: Fields, construction, dispatch operations, listeners, and timeout accessors are logically organized into focused methods. Nesting: Mostly flat, with modest nesting in synchronization blocks and listener exception handling. Clarity of intent: Descriptive names, interface overrides, and nullability annotations make behavior clear; the hexadecimal timeout expression obscures a simple 10000 value, and unused parameters in mock implementations could benefit from explanation. Code length: Methods are concise, though the timeout documentation is comparatively lengthy and some overloads repeat behavior. Action granularity: Statements generally perform one action per line, making state changes and callbacks easy to follow. Reading flow: Consistent formatting and straightforward delegation support natural reading, although tightly packed imports, extra blank lines, and a long type-check expression slightly reduce visual polish.