Sample

int-29599b1c1df4-I13

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

Matched original source

Lines71

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.650–1; higher is more readable
Dorn0.6550–1; higher is more readable
Mi0.090–1; higher is more readable
LLOC18Logical lines; fewer is more readable
DeepSeek V4 Pro17.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.5680–1; higher is more readable

Views

Source code

package org.apache.kafka.common.security.oauthbearer; import org.apache.kafka.common.annotation.InterfaceAudience; import org.apache.kafka.common.security.oauthbearer.internals.secured.ClientAssertionRequestFormatter; import org.apache.kafka.common.security.oauthbearer.internals.secured.ClientSecretRequestFormatter; import org.apache.kafka.common.security.oauthbearer.internals.secured.ConfigurationUtils; import org.apache.kafka.common.utils.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.URL; import java.util.List; import java.util.Locale; import java.util.Map; import javax.security.auth.login.AppConfigurationEntry; import static org.apache.kafka.common.config.SaslConfigs.SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL; /** * {@code DefaultJwtRetriever} instantiates and delegates {@link JwtRetriever} API calls to an embedded implementation * based on configuration: * * <ul> * <li> * If the value of <code>sasl.oauthbearer.token.endpoint.url</code> is set to a value that starts with the * <code>file</code> protocol (e.g. <code>file:/tmp/path/to/a/static-jwt.json</code>), an instance of * {@link FileJwtRetriever} will be used as the underlying {@link JwtRetriever}. Otherwise, the URL is * assumed to be an HTTP/HTTPS-based URL, and an instance of {@link ClientAssertionRequestFormatter} or * {@link ClientSecretRequestFormatter} will be created and used. * </li> * </ul> * * The configuration required by the individual {@code JwtRetriever} classes will likely differ. Please refer to the * official Apache Kafka documentation for more information on these, and related configuration. */ @InterfaceAudience.Public public class DefaultJwtRetriever implements JwtRetriever { private static final Logger LOG = LoggerFactory.getLogger(DefaultJwtRetriever.class); private JwtRetriever delegate; @Override public void configure(Map<String, ?> configs, String saslMechanism, List<AppConfigurationEntry> jaasConfigEntries) { ConfigurationUtils cu = new ConfigurationUtils(configs, saslMechanism); URL tokenEndpointUrl = cu.validateUrl(SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL); if (tokenEndpointUrl.getProtocol().toLowerCase(Locale.ROOT).equals("file")) delegate = new FileJwtRetriever(); else delegate = new ClientCredentialsJwtRetriever(); LOG.debug("Created instance of {} as delegate", delegate.getClass().getName()); delegate.configure(configs, saslMechanism, jaasConfigEntries); } @Override public String retrieve() throws JwtRetrieverException { if (delegate == null) throw new IllegalStateException("JWT retriever delegate is null; please call configure() first"); return delegate.retrieve(); } @Override public void close() throws IOException { Utils.closeQuietly(delegate, "JWT retriever delegate"); } JwtRetriever delegate() { return delegate; } }

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.2411.137−79.568
Source linesThe number of non-empty source lines.71+28.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.4.926−7.389

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

Score0.65

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.72−1.513
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.119.972−1.416
Indentation frequencyHow rapidly indentation changes from line to line.55+1.165
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.111.736+0.998
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.70.876+0.581
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.06+0.358

Intercept 0.07 + feature contributions = 0.641 (log-odds).
Score = sigmoid(0.641) = 0.655.

Score0.09
Score18
Run 1

The code is highly readable and well-structured. It maintains a flat structure with minimal nesting (a simple if-else and a null check), making control flow easy to follow. Intent is clear: DefaultJwtRetriever acts as a delegating facade that selects an implementation based on the token endpoint URL protocol. Variable names are descriptive (e.g., delegate, tokenEndpointUrl), and logging improves observability. The configure method is concise, delegating URL validation and configuration to ConfigurationUtils. Each line performs one logical action, improving readability. The class is compact and avoids unnecessary verbosity. The helper method delegate() provides testability without clutter. Minor improvements could include adding braces to the single-line if/else statements to fully prevent possible ambiguity, but overall the code is exemplary.

Run 2

The code is well-structured and readable. The class has a clear single responsibility: delegating JwtRetriever operations based on configuration. Imports are organized, and the Javadoc provides helpful context. The configure method is logically sequenced: validate URL, determine protocol, instantiate delegate, log, and delegate configuration. Nesting is minimal with only a single if-else branch. The retrieve method has a simple guard clause. Action granularity is appropriate—one logical action per line. The reading flow is natural, with the delegation pattern clearly visible. Minor deductions: the if-else could use braces for consistency, and the delegate() method has package-private visibility without an obvious reason, slightly obscuring intent. Overall, the code is concise, maintains flat nesting, and clearly communicates its purpose.

Run 3

The code is generally clear and well-structured. It uses a straightforward delegation pattern, with a single if/else block in configure() that has low nesting. Intent is evident from the naming and concise Javadoc. Most lines perform one action, and the reading flow follows a logical sequence (validate config, select delegate, delegate the call). The main readability drawbacks are minor: the if/else in configure() lacks braces, which can be fragile but is still compact; the condition compares the lowercased protocol against a literal string, which is clear but slightly verbose. The class is concise, delegates responsibility appropriately, and avoids deep nesting. Additional points could be gained by using braces consistently, perhaps extracting delegate selection into a helper, or improving the Javadoc example formatting, but these are relatively small issues. Overall, the code is readable and maintainable.

Run 1

Code Structure: Well-organized delegation class with clearly separated configuration, retrieval, and cleanup methods. Nesting: Minimal; simple conditionals and an early validation guard keep control flow flat. Clarity of intent: Descriptive class and method names make the purpose clear, although 'cu' is abbreviated and the Javadoc misleadingly describes request formatters rather than the actual HTTP retriever instantiated. Code length: Implementation is concise with little unnecessary code; documentation is somewhat verbose. Action granularity: Each statement performs a distinct action, with no crowded multi-statement lines. Reading flow: Methods follow a natural lifecycle order, and delegate selection is easy to trace. Missing braces around conditionals and tightly packed imports slightly reduce visual consistency.

Run 2

Code Structure: Well-organized class with distinct configuration, retrieval, cleanup, and accessor methods. Nesting: Minimal; simple conditionals keep execution paths easy to follow, although braces would improve consistency. Clarity of intent: Descriptive class and method names make delegation clear. However, the abbreviated variable 'cu' and documentation describing request formatters rather than the instantiated ClientCredentialsJwtRetriever slightly reduce clarity. Code length: Implementation is concise, though the documentation is comparatively verbose. Action granularity: Each statement performs a focused action, with no crowded multi-statement lines. Reading flow: Configuration naturally precedes retrieval and cleanup, and the null guard clearly communicates the initialization requirement. Tightly packed imports and omitted conditional braces are minor presentation weaknesses.

Run 3

Code Structure: Clearly organized around configuration, retrieval, cleanup, and delegate access, with a straightforward delegation pattern. Nesting: Minimal; only simple conditionals, although omitted braces slightly reduce visual clarity. Clarity of intent: Descriptive class and method names make the purpose clear, but the abbreviated variable 'cu' is less expressive, and the Javadoc describes request formatters rather than the actual HTTP delegate instantiated. Code length: Implementation is concise, though the documentation is somewhat verbose for a simple selection rule. Action granularity: Each statement performs a distinct action, with no crowded multi-statement lines. Reading flow: Methods follow a natural lifecycle order, and configuration reads sequentially from validation to delegate selection and initialization. Import grouping and spacing could be improved.