Sample

int-ec59393a0297-I13

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

Matched original source

Lines72

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.3810–1; higher is more readable
Dorn0.0040–1; higher is more readable
Mi0.3310–1; higher is more readable
LLOC28Logical lines; fewer is more readable
DeepSeek V4 Pro14.330–20; mean of three runs
GPT-6.1 Sol14.330–20; mean of three runs
BTTF0.290–1; higher is more readable

Views

Source code

package io.netty.testsuite.transport.socket; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.EventLoopGroup; import io.netty.channel.IoEventLoopGroup; import io.netty.channel.nio.NioIoHandler; import io.netty.testsuite.transport.TestsuitePermutation; import io.netty.util.NetUtil; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.Timeout; import java.nio.channels.AlreadyConnectedException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertTrue; public class SocketMultipleConnectTest extends AbstractSocketTest { @Test @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS) public void testMultipleConnect(TestInfo testInfo) throws Throwable { run(testInfo, new Runner<ServerBootstrap, Bootstrap>() { @Override public void run(ServerBootstrap serverBootstrap, Bootstrap bootstrap) throws Throwable { testMultipleConnect(serverBootstrap, bootstrap); } }); } public void testMultipleConnect(ServerBootstrap sb, Bootstrap cb) throws Exception { Channel sc = null; Channel cc = null; try { sb.childHandler(new ChannelInboundHandlerAdapter()); sc = sb.bind(NetUtil.LOCALHOST, 0).syncUninterruptibly().channel(); cb.handler(new ChannelInboundHandlerAdapter()); cc = cb.register().syncUninterruptibly().channel(); cc.connect(sc.localAddress()).syncUninterruptibly(); ChannelFuture connectFuture2 = cc.connect(sc.localAddress()).await(); assertTrue(connectFuture2.cause() instanceof AlreadyConnectedException); } finally { if (cc != null) { cc.close(); } if (sc != null) { sc.close(); } } } @Override protected List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> newFactories() { List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> factories = new ArrayList<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>>(); { java.util.Iterator<?> loopIterator = (SocketTestPermutation.INSTANCE.socketWithFastOpen()).iterator(); while (loopIterator.hasNext()) { TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap> comboFactory = (TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>) loopIterator.next(); EventLoopGroup group = comboFactory.newClientInstance().config().group(); if (group instanceof IoEventLoopGroup && ((IoEventLoopGroup) group).isIoType(NioIoHandler.class)) { factories.add(comboFactory); } } } return factories; } }

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.3874.249−127.85
Source linesThe number of non-empty source lines.72+28.8
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.682−7.023

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

Score0.381

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.190.986−4.424
Indentation frequencyHow rapidly indentation changes from line to line.72+1.753
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.73−1.548
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.72−1.231
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.71.885+0.595
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.102−0.05

Intercept 0.07 + feature contributions = -5.64 (log-odds).
Score = sigmoid(-5.64) = 0.004.

Score0.331
Score28
Run 1

The code demonstrates excellent readability with clear logical structure, minimal nesting, and well-separated concerns. The test method properly delegates to a runner pattern, keeping the actual test logic focused and manageable. Variable names are appropriately concise (sc/cc for server/client channels), and the try-finally cleanup block shows clear intent for resource management. The `newFactories()` method uses a single level of nesting and includes a descriptive iterator variable name, making the filtering logic easy to follow. Each line performs one logical action, and the reading flow progresses naturally from setup through assertion to cleanup. The only minor complexity is the generic type declarations in the factories method, but this is necessary Java verbosity rather than a design issue. Overall, the code is maintainable, self-documenting, and follows clean code principles.

Run 2

The code has a clear structure with separate methods for test execution and factory creation, and it follows standard Java conventions. However, the `newFactories()` method is unnecessarily verbose with a redundant block, manual iterator, and unchecked cast. The `testMultipleConnect` method uses multiple operations per line chained with `syncUninterruptibly()`, which reduces readability and makes it harder to follow the flow. Variable names like `sb`, `cb`, `sc`, and `cc` are short but reasonable given their scopes. The try/finally cleanup is straightforward. Overall, the intent is understandable but the implementation has avoidable boilerplate and dense chaining that obscure the logic.

Run 3

The code has clear structure with logical separation of test methods and setup, but suffers from verbose generics and redundant type declarations in newFactories(). Nesting is moderate - the anonymous Runner class adds a layer but is a standard pattern. Clarity of intent is good in testMultipleConnect with descriptive variable names and obvious assertions. However, the newFactories() method is unnecessarily long with repeated fully-qualified generic types and an awkward manual iterator loop that could use a for-each or stream. Action granularity is mostly one action per line, aiding readability. Reading flow is natural in the main test but disrupted by the verbose factory setup. The try-finally cleanup is well-structured. Overall, the code is readable but could be significantly improved by using diamond operators, simplifying the iterator logic, and reducing generic verbosity.

Run 1

Code Structure: Test execution, connection checks, and factory filtering are logically separated into methods. Nesting: Mostly shallow, although the redundant block and while/if nesting in newFactories add clutter. Clarity of intent: The test clearly verifies that a second connection fails with AlreadyConnectedException; abbreviated names such as sb, cb, sc, and cc reduce clarity. Code length: Reasonably compact overall, but the anonymous runner, repeated generic types, and explicit iterator with casts are verbose. Action granularity: Statements generally perform one main action per line, though chained asynchronous operations and a long cast-heavy declaration require extra parsing. Reading flow: Setup, execution, assertion, and cleanup follow a natural sequence. However, inconsistent indentation, fully qualified Iterator usage, and dense generic declarations disrupt the otherwise straightforward flow.

Run 2

Code Structure: Test execution, connection verification, cleanup, and factory filtering are logically separated, though the extra block in newFactories is unnecessary. Nesting: Mostly shallow; the anonymous runner and block/while/if combination add moderate nesting. Clarity of intent: The test clearly verifies that a second connection fails with AlreadyConnectedException, but abbreviated names (sb, cb, sc, cc) and verbose generic types reduce immediate understanding. Code length: Reasonably compact overall, although the explicit iterator, unchecked cast, and repeated generic declaration could be simplified. Action granularity: Most lines perform one coherent action; fluent call chains are conventional and understandable. Reading flow: Setup, execution, assertion, and cleanup follow a natural sequence. The factory-filtering method interrupts that clarity with inconsistent indentation, a fully qualified Iterator, a very long cast line, and an unnecessary scope block.

Run 3

Code Structure: Test execution, connection verification, cleanup, and factory filtering are separated into methods, but the unnecessary block in newFactories adds clutter. Nesting: Mostly shallow; the anonymous runner and block/while/if combination introduce moderate nesting. Clarity of intent: The test name and AlreadyConnectedException assertion clearly communicate the purpose, while abbreviated names such as sb, cb, sc, and cc reduce clarity. Code length: Reasonably short, but the explicit iterator, repeated generic types, casts, and anonymous runner are verbose. Action granularity: Most lines perform one logical action, although chained setup calls and the long iterator-cast assignment are harder to scan. Reading flow: The setup-connect-assert-cleanup sequence reads naturally; inconsistent indentation, dense generic declarations, and fully qualified iterator usage disrupt the factory-filtering section.