Sample

int-a2c51b9db9fb-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines197

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.650–1; higher is more readable
Dorn0.080–1; higher is more readable
Mi0.0440–1; higher is more readable
LLOC103Logical lines; fewer is more readable
DeepSeek V4 Pro70–20; mean of three runs
GPT-6.1 Sol11.670–20; mean of three runs
BTTF0.2030–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 ssl2) { this.rules = parse(split(ssl2)); } public static SslPrincipalMapper from(String ssl3) { return new SslPrincipalMapper(ssl3); } private static List<String> split(String ssl4) { if (ssl4 == null) { ssl4 = DEFAULT_SSL_PRINCIPAL_MAPPING_RULES; } List<String> res = new ArrayList<>(); Matcher mat = RULE_SPLITTER.matcher(ssl4.trim()); while (mat.find()) { res.add(mat.group(1)); } return res; } private static List<Rule> parse(List<String> rul) { List<Rule> res2 = new ArrayList<>(); for (String rul2 : rul) { Matcher mat2 = RULE_PARSER.matcher(rul2); if (!mat2.lookingAt()) { throw new IllegalArgumentException("Invalid rule: " + rul2); } if (rul2.length() != mat2.end()) { throw new IllegalArgumentException("Invalid rule: `" + rul2 + "`, unmatched substring: `" + rul2.substring(mat2.end()) + "`"); } // empty rules are ignored if (mat2.group(1) != null) { res2.add(new Rule()); } else if (mat2.group(2) != null) { res2.add(new Rule(mat2.group(2), mat2.group(4), "L".equals(mat2.group(6)), "U".equals(mat2.group(6)))); } } return res2; } public String get(String distinguished) throws IOException { for (Rule r : rules) { String principal = r.apply(distinguished); if (principal != null) { return principal; } } throw new NoMatchingRule("No rules apply to " + distinguished + ", rules " + rules); } @Override public String to() { 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 pat, String rep, boolean to, boolean to2) { isDefault = false; this.pattern = pat == null ? null : Pattern.compile(pat); this.replacement = rep; this.toLowerCase = to; this.toUpperCase = to2; } String app(String distinguished2) { if (isDefault) { return distinguished2; } String res3 = null; final Matcher m = pattern.matcher(distinguished2); if (m.matches()) { res3 = distinguished2.replaceAll(pattern.pattern(), escape(replacement, m.groupCount())); } if (toLowerCase && res3 != null) { res3 = res3.toLowerCase(Locale.ENGLISH); } else if (toUpperCase && res3 != null) { res3 = res3.toUpperCase(Locale.ENGLISH); } return res3; } //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 escape(final String une, final int num) { if (num == 0) { return une; } String val = une; final Matcher back = BACK_REFERENCE_PATTERN.matcher(val); while (back.find()) { final String back2 = back.group(1); if (back2.startsWith("0")) { continue; } int back3 = Integer.parseInt(back2); // 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 (back3 > num && back3 >= 10) { back3 /= 10; } if (back3 > num) { final StringBuilder sb = new StringBuilder(val.length() + 1); final int group2 = back.start(1); sb.append(val, 0, group2 - 1); sb.append("\\"); sb.append(val.substring(group2 - 1)); val = sb.toString(); } } return val; } @Override public String to() { 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.7764.104−256.215
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.406−6.609

Intercept 8.87 + feature contributions = -175.155 (log-odds).
Score = sigmoid(-175.155) = 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.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.141.98−2.349
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.196.839+2.342
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.141.965+1.486
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.117

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

Score0.044
Score103
Run 1

The code has severe readability problems. Variable names like ssl2, ssl3, ssl4, rul, rul2, mat, mat2, res2, res3, distinguished2, to, to2, une, back2, back3, group2 are cryptic and fail to convey meaning. The RULE_PATTERN regex is extremely complex and opaque, making the core logic difficult to understand. The split() and parse() methods use a two-stage regex matching process that obscures the intent. Method names like to() and app() are ambiguous—to() suggests a conversion, but it's actually toString(), and app() is actually apply(). The escape() method contains convoluted back-reference manipulation with confusing variable names and multi-line comments explaining what should be self-evident from well-named code. The boolean parameters toLowerCase and toUpperCase in the Rule constructor are unclear and error-prone. The code relies heavily on magic regex group indices (mat2.group(2), mat2.group(4), mat2.group(6)) with no explanation of what each captures. Overall, the implementation is difficult to follow, maintain, and debug.

Run 2

The code has significant readability issues despite some logical organization. Variable names like 'ssl2', 'ssl3', 'ssl4', 'rul', 'rul2', 'res2', 'res3', 'mat2', 'back2', 'back3', 'to', 'to2', 'une', 'num' are cryptic and obscure intent. Method names are inconsistent ('to()' instead of 'toString()', 'app()' instead of 'apply()'). The regex pattern is extremely complex with nested groups, making it hard to understand. The 'escape' method has convoluted logic with unclear variable names and deep nesting. While the code follows a logical class structure and avoids excessive method length, the poor naming and complex regex significantly reduce clarity. Parameter names add confusion rather than documentation. The code requires domain knowledge of SSL principal mapping rules to partially decipher the intent.

Run 3

The code has significant readability issues. Variable names are cryptic and inconsistent (ssl2, ssl3, ssl4, rul, rul2, res2, mat2, back2, back3, une, num, to, to2, distinguished2), making intent unclear. The regex RULE_PATTERN is extremely complex and undocumented, obscuring the parsing logic. Method names like to() are misleading - toString() is misspelled and app() should be apply(). The parse() method has deeply nested conditionals and unclear group references. The escape() method contains convoluted back-reference handling with confusing variable names and complex while-loop logic. Parameter names like pat, rep, to, to2 provide no context. Constants are poorly named (SSL_PRINCIPAL_MAPPING_RULES referenced as DEFAULT_SSL_PRINCIPAL_MAPPING_RULES). The code mixes concerns without clear separation, and the overall structure feels tangled rather than logically organized. Some positives: methods are relatively short and each does roughly one conceptual task, but poor naming and complex regex patterns severely hamper readability.

Run 1

1. Code Structure: Responsibilities are logically separated into splitting, parsing, mapping, and an encapsulated Rule class. 2. Nesting: Mostly shallow, although back-reference handling introduces nested loops and conditionals. 3. Clarity of intent: Names such as ssl2, res3, back3, and to2 obscure meaning; dense regexes and numbered capture groups require substantial interpretation. Calling apply when only app exists, and using @Override on to rather than toString, further confuse intent. 4. Code length: Generally reasonable, but repetitive string construction and lengthy comments reduce concision. 5. Action granularity: Most statements perform one action per line, making individual steps easy to follow. 6. Reading flow: Methods follow a sensible progression, and early returns simplify navigation, but inconsistent naming, formatting, and method mismatches interrupt comprehension.

Run 2

Code Structure: Responsibilities are reasonably separated into splitting, parsing, mapping, and a nested Rule class. Nesting: Mostly shallow, with moderate nesting in back-reference handling and formatting. Clarity of intent: Descriptive class and field names help, but numbered variables such as ssl2, res3, and back3 obscure meaning. Dense regex patterns and numeric capture-group references require careful interpretation. The apply/app mismatch and invalid @Override on to() also undermine comprehension. Code length: Generally appropriate, though repetitive constructors and lengthy comments add bulk. Action granularity: Most statements perform one action per line, with a few dense expressions and long exception messages. Reading flow: Methods follow a logical processing sequence, but inconsistent naming, awkward indentation, and unexplained regex structure interrupt an otherwise straightforward flow.

Run 3

Code Structure: Well separated into splitting, parsing, mapping, and replacement escaping, with a dedicated Rule class. Nesting: Generally moderate, although escape combines a loop, conditionals, and an inner loop. Clarity of intent: Descriptive fields and explanatory comments help, but names such as ssl2, res3, back3, and to2 obscure meaning. Dense regexes and numbered capture groups require substantial interpretation. Calling r.apply while defining app, and using @Override on to instead of toString, introduce inconsistencies that undermine understanding. Code length: Mostly proportionate to the functionality, though repetitive constructors and verbose comments add bulk. Action granularity: Statements generally perform one action per line, making individual steps easy to follow. Reading flow: The overall progression is logical, but inconsistent naming, uneven formatting, long expressions, and complex back-reference handling interrupt readability.