Sample

int-d9965c2d11ef-I01

Remove line comments, block comments, and Javadoc

Matched original source

Lines197

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.5820–1; higher is more readable
Dorn0.0080–1; higher is more readable
Mi0.0530–1; higher is more readable
LLOC103Logical lines; fewer is more readable
DeepSeek V4 Pro12.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.190–1; higher is more readable

Views

Source code

package org.apache.kafka.common.security.ssl; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; import static org.apache.kafka.common.config.internals.BrokerSecurityConfigs.DEFAULT_SSL_PRINCIPAL_MAPPING_RULES; public class SslPrincipalMapper { private static final String RULE_PATTERN = "(DEFAULT)|RULE:((\\\\.|[^\\\\/])*)/((\\\\.|[^\\\\/])*)/([LU]?).*?|(.*?)"; private static final Pattern RULE_SPLITTER = Pattern.compile("\\s*(" + RULE_PATTERN + ")\\s*(,\\s*|$)"); private static final Pattern RULE_PARSER = Pattern.compile(RULE_PATTERN); private final List<Rule> rules; public SslPrincipalMapper(String sslPrincipalMappingRules) { this.rules = parseRules(splitRules(sslPrincipalMappingRules)); } public static SslPrincipalMapper fromRules(String sslPrincipalMappingRules) { return new SslPrincipalMapper(sslPrincipalMappingRules); } private static List<String> splitRules(String sslPrincipalMappingRules) { if (sslPrincipalMappingRules == null) { sslPrincipalMappingRules = DEFAULT_SSL_PRINCIPAL_MAPPING_RULES; } List<String> result = new ArrayList<>(); Matcher matcher = RULE_SPLITTER.matcher(sslPrincipalMappingRules.trim()); while (matcher.find()) { result.add(matcher.group(1)); } return result; } private static List<Rule> parseRules(List<String> rules) { List<Rule> result = new ArrayList<>(); for (String rule : rules) { Matcher matcher = RULE_PARSER.matcher(rule); if (!matcher.lookingAt()) { throw new IllegalArgumentException("Invalid rule: " + rule); } if (rule.length() != matcher.end()) { throw new IllegalArgumentException("Invalid rule: `" + rule + "`, unmatched substring: `" + rule.substring(matcher.end()) + "`"); } if (matcher.group(1) != null) { result.add(new Rule()); } else if (matcher.group(2) != null) { result.add(new Rule(matcher.group(2), matcher.group(4), "L".equals(matcher.group(6)), "U".equals(matcher.group(6)))); } } return result; } public String getName(String distinguishedName) throws IOException { for (Rule r : rules) { String principalName = r.apply(distinguishedName); if (principalName != null) { return principalName; } } throw new NoMatchingRule("No rules apply to " + distinguishedName + ", rules " + rules); } @Override public String toString() { return "SslPrincipalMapper(rules = " + rules + ")"; } public static class NoMatchingRule extends IOException { NoMatchingRule(String msg) { super(msg); } } private static class Rule { private static final Pattern BACK_REFERENCE_PATTERN = Pattern.compile("\\$(\\d+)"); private final boolean isDefault; private final Pattern pattern; private final String replacement; private final boolean toLowerCase; private final boolean toUpperCase; Rule() { isDefault = true; pattern = null; replacement = null; toLowerCase = false; toUpperCase = false; } Rule(String pattern, String replacement, boolean toLowerCase, boolean toUpperCase) { isDefault = false; this.pattern = pattern == null ? null : Pattern.compile(pattern); this.replacement = replacement; this.toLowerCase = toLowerCase; this.toUpperCase = toUpperCase; } String apply(String distinguishedName) { if (isDefault) { return distinguishedName; } String result = null; final Matcher m = pattern.matcher(distinguishedName); if (m.matches()) { result = distinguishedName.replaceAll(pattern.pattern(), escapeLiteralBackReferences(replacement, m.groupCount())); } if (toLowerCase && result != null) { result = result.toLowerCase(Locale.ENGLISH); } else if (toUpperCase && result != null) { result = result.toUpperCase(Locale.ENGLISH); } return result; } private String escapeLiteralBackReferences(final String unescaped, final int numCapturingGroups) { if (numCapturingGroups == 0) { return unescaped; } String value = unescaped; final Matcher backRefMatcher = BACK_REFERENCE_PATTERN.matcher(value); while (backRefMatcher.find()) { final String backRefNum = backRefMatcher.group(1); if (backRefNum.startsWith("0")) { continue; } int backRefIndex = Integer.parseInt(backRefNum); while (backRefIndex > numCapturingGroups && backRefIndex >= 10) { backRefIndex /= 10; } if (backRefIndex > numCapturingGroups) { final StringBuilder sb = new StringBuilder(value.length() + 1); final int groupStart = backRefMatcher.start(1); sb.append(value, 0, groupStart - 1); sb.append("\\"); sb.append(value.substring(groupStart - 1)); value = sb.toString(); } } return value; } @Override public String toString() { StringBuilder buf = new StringBuilder(); if (isDefault) { buf.append("DEFAULT"); } else { buf.append("RULE:"); if (pattern != null) { buf.append(pattern); } if (replacement != null) { buf.append("/"); buf.append(replacement); } if (toLowerCase) { buf.append("/L"); } else if (toUpperCase) { buf.append("/U"); } } return buf.toString(); } } }

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.7639.316−252.097
Source linesThe number of non-empty source lines.197+78.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.409−6.613

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

Score0.582

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.197+6.077
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.198−5.974
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.197−4.1
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.144.985−2.476
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.196.815+2.341
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.088+0.084

Intercept 0.07 + feature contributions = -4.782 (log-odds).
Score = sigmoid(-4.782) = 0.008.

Score0.053
Score103
Run 1

The code has a reasonable high-level structure with clear separation of concerns between parsing and rule application, and the class/method responsibilities are logically organized. However, readability suffers from several issues. The regex patterns are extremely complex and cryptic, especially RULE_PATTERN with its nested groups and escaped characters, making intent very difficult to understand without extensive documentation. The escapeLiteralBackReferences method contains confusing logic with unexplained arithmetic operations on back-reference indices and sparse comments that only partially clarify the reasoning. Nesting is moderate, though the escapeLiteralBackReferences method has multiple nested control structures and mutation of local variables that complicate tracing. Action granularity is generally good with one operation per line, but the heavy reliance on regex and the opaque back-reference normalization logic means each line is not necessarily straightforward to interpret. The reading flow is adequate for the main methods but breaks down in the complex string manipulation sections. Overall, the code is functional but requires significant domain knowledge and careful study of the regex patterns to fully understand.

Run 2

The code shows moderate readability with clear class structure and method separation. The main issues are: overly complex regex patterns that are hard to understand, the cryptic RULE_PATTERN constant with escaping that obscures intent, and inconsistent formatting in parseRules with unnecessary blank lines. The escapeLiteralBackReferences method has complex logic with nested while loops and unclear comments. However, the code benefits from good naming conventions (SslPrincipalMapper, Rule, apply), reasonable method lengths, and logical grouping of related functionality. The Rule class is well-encapsulated with clear fields. Error handling is adequate with descriptive exception messages. The overall flow from parsing rules to applying them is understandable, but the regex-heavy implementation significantly reduces overall readability for developers unfamiliar with the specific pattern syntax being parsed.

Run 3

The code has reasonable top-level structure with clear class responsibilities, but suffers from several readability issues. The regex pattern RULE_PATTERN is extremely complex and poorly documented, making intent difficult to grasp. The parseRules method has confusing group-index logic and a stray comment. The escapeLiteralBackReferences method contains convoluted index arithmetic with inadequate explanation. While most methods are short and do one thing, the nested regex parsing and back-reference handling create high cognitive load. Naming is generally good, and action granularity is mostly fine, but the nested while loops and obscure comments reduce clarity. Overall, the code is maintainable but requires deep regex expertise to understand safely.

Run 1

Code Structure: Well organized into rule splitting, parsing, application, and formatting, with rule behavior encapsulated in a nested class. Nesting: Generally shallow, though back-reference handling and formatting introduce moderate nesting. Clarity of intent: Descriptive method and field names communicate the overall purpose, but dense regular expressions, numbered capture groups, abbreviated variables, and undocumented back-reference logic require careful interpretation. Code length: Mostly proportionate to functionality, although repetitive initialization and excessive blank lines add noise. Action granularity: Statements generally perform one action per line; a few long expressions combine several operations and hinder scanning. Reading flow: Methods follow a natural progression from construction to parsing and execution, but complex regex details and unexplained edge-case handling interrupt otherwise smooth reading.

Run 2

Code Structure: Well organized into focused methods for splitting, parsing, and applying rules, with rule behavior encapsulated in an inner class. Nesting: Mostly shallow, though back-reference escaping and rule formatting introduce moderate nesting. Clarity of intent: Descriptive method and field names communicate the purpose, but dense regex patterns, numbered capture groups, short variables, and undocumented back-reference handling require careful interpretation. Code length: Generally concise for its functionality, although repeated validation and excessive blank lines add clutter. Action granularity: Most statements perform one action per line; a few long expressions and constructor calls increase cognitive load. Reading flow: Progresses naturally from construction through parsing to application, but unexplained regex details and irregular whitespace interrupt otherwise consistent formatting.

Run 3

Code Structure: Well organized into rule splitting, parsing, application, and a dedicated nested Rule class. Nesting: Mostly shallow, though back-reference handling and rule formatting introduce moderate nesting. Clarity of intent: Descriptive method and field names communicate the mapping purpose, but dense regular expressions, numeric matcher groups, and undocumented back-reference logic require careful interpretation. Code length: Generally appropriate for the functionality, with some repetitive string construction and distracting excess blank lines. Action granularity: Nearly all statements perform one action per line; a few long expressions and exception messages increase reading effort. Reading flow: Methods follow a natural progression from configuration parsing to mapping execution, but opaque regex details and abbreviated variables such as r and m interrupt otherwise clear flow.