Sample

int-95140222faff-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines197

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6220–1; higher is more readable
Dorn0.080–1; higher is more readable
Mi0.0530–1; higher is more readable
LLOC103Logical lines; fewer is more readable
DeepSeek V4 Pro11.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.20–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()) + "`"); } // empty rules are ignored 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; } //If we find a back reference that is not valid, then we will treat it as a literal string. For example, if we have 3 capturing //groups and the Replacement Value has the value is "$1@$4", then we want to treat the $4 as a literal "$4", rather //than attempting to use it as a back reference. //This method was taken from Apache Nifi project : org.apache.nifi.authorization.util.IdentityMappingUtil 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); // if we have a replacement value like $123, and we have less than 123 capturing groups, then // we want to truncate the 3 and use capturing group 12; if we have less than 12 capturing groups, // then we want to truncate the 2 and use capturing group 1; if we don't have a capturing group then // we want to truncate the 1 and get 0. 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.473−6.71

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

Score0.622

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.198−5.974
Indentation frequencyHow rapidly indentation changes from line to line.188+5.766
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.188−3.893
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.144.97+1.535
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.078+0.187

Intercept 0.07 + feature contributions = -2.445 (log-odds).
Score = sigmoid(-2.445) = 0.08.

Score0.053
Score103
Run 1

The code has clear class responsibilities and reasonable method decomposition, but readability is hurt by several factors. The regex `RULE_PATTERN` is highly obscure, making parsing logic difficult to understand. `parseRules` uses regex groups whose meanings are not documented, reducing clarity of intent. Nested `if/else if` in `apply` is mild but acceptable. The `escapeLiteralBackReferences` method is long and the backreference truncation logic is complex and only briefly commented. Comments are helpful but lengthy. Some lines are dense, especially regex pattern definitions and the nested `Rule` constructor call. Action granularity is mostly one action per line, but regex-heavy lines pack too much. Overall, the code is maintainable but would benefit from clearer parsing abstractions and better explanation of the rule grammar.

Run 2

The code shows good organization with clear class structure and method separation, but readability is significantly hindered by several factors. The regex patterns (RULE_PATTERN) are extremely complex and lack documentation, making the pattern matching logic nearly impossible to understand. The nested while loops in escapeLiteralBackReferences create deeper nesting with complex string manipulation. There is inconsistent action granularity - rule parsing combines multiple operations per line, while other areas are well-spaced. The intent of the regex-based rule parsing is ambiguous without extensive comments explaining the expected input format. The code length is justified but the escapeLiteralBackReferences method with its multiple nested loops could be simplified. Reading flow is disrupted by the complex regex pattern at the top and the intricate back-reference handling logic.

Run 3

The code has clear class/method separation and reasonable naming, but suffers from several readability issues. The regex patterns are extremely dense and undocumented (RULE_PATTERN, RULE_SPLITTER) making intent hard to grasp. The rule parsing logic in parseRules uses magic group indices (matcher.group(2), group(4), group(6)) without explanation. The apply method mixes matching and replacement logic in ways that are not obvious. escapeLiteralBackReferences contains a complex nested loop and integer truncation logic that, while commented, remains difficult to follow. Nesting is moderate but the while-loop inside the method adds cognitive load. Some methods are concise and single-purpose (splitRules, fromRules), but the overall action granularity is inconsistent. Reading flow is disrupted by intricate regex handling and unclear group references.

Run 1

Code Structure: Responsibilities are logically separated into splitting, parsing, mapping, and a nested Rule class. Nesting: Mostly shallow, although back-reference handling and rule formatting introduce moderate nesting. Clarity of intent: Descriptive method and field names communicate purpose, and comments explain tricky replacement behavior; dense regex patterns, numbered capture groups, and abbreviated variables such as r and m reduce clarity. Code length: Generally appropriate, but verbose initialization, formatting logic, and lengthy comments add some bulk. Action granularity: Statements usually perform one action per line, though rule construction and replacement expressions combine several operations. Reading flow: The progression from configuration parsing to rule application is natural, with early returns simplifying control flow. Long expressions and subtle matcher/string manipulation interrupt otherwise smooth reading.

Run 2

Code Structure: Well-organized methods separate splitting, parsing, mapping, and back-reference handling; the nested Rule class encapsulates rule behavior. Nesting: Generally shallow, with moderate nesting in parsing, back-reference processing, and string formatting. Clarity of intent: Descriptive method and field names communicate purpose, and comments explain tricky replacement semantics. However, dense regular expressions, numbered capture groups, and abbreviated variables such as r and m require extra interpretation. Code length: Mostly proportionate to functionality, though repetitive initialization, verbose string construction, and lengthy comments slightly reduce concision. Action granularity: Most statements perform one action per line; a few long expressions combine several operations and hinder scanning. Reading flow: The progression from configuration parsing to rule application is natural, with consistent formatting overall. Minor spacing inconsistencies and the intricate back-reference algorithm interrupt otherwise smooth reading.

Run 3

Code Structure: Well-organized into rule splitting, parsing, application, and a focused nested Rule class. Nesting: Mostly shallow, with moderate nesting in back-reference handling and string formatting. Clarity of intent: Descriptive method and field names communicate the mapping workflow, but dense regular expressions, numbered capture groups, and abbreviated variables such as r and m require extra interpretation. Code length: Generally proportionate to the functionality, though constructor initialization, formatting logic, and lengthy comments add some verbosity. Action granularity: Statements generally perform one action per line; a few chained expressions and long exception messages are harder to scan. Reading flow: The progression from construction to parsing to application is natural, and early returns simplify control flow. Complex back-reference manipulation, inconsistent comment formatting, and occasional long lines interrupt otherwise clear reading.