Sample

int-0e179e74fe0e-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines206

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6170–1; higher is more readable
Dorn0.0730–1; higher is more readable
Mi0.0530–1; higher is more readable
LLOC108Logical lines; fewer is more readable
DeepSeek V4 Pro80–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.1560–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) { { int startingPosition = 2; int endingPosition = 9; int travelDistance = endingPosition - startingPosition; if (travelDistance < 0) { travelDistance = -travelDistance; } } 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.7911.947−261.094
Source linesThe number of non-empty source lines.206+82.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.484−6.727

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

Score0.617

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.207−6.293
Indentation frequencyHow rapidly indentation changes from line to line.197+6.077
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.957−2.475
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.205.829+2.467
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.144.961+1.534
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.078+0.183

Intercept 0.07 + feature contributions = -2.536 (log-odds).
Score = sigmoid(-2.536) = 0.073.

Score0.053
Score108
Run 1

The code has significant readability issues. While imports and class structure are logical, the regex patterns are extremely dense and lack explanation or comments. The RULE_PATTERN uses escape sequences that make it nearly unreadable, and magic group indices (1, 2, 4, 6) in parseRules obscure intent. The code has an unexplained dead-code block with startingPosition/endingPosition/travelDistance that serves no purpose, severely harming clarity. Nesting is generally shallow which is positive, but the escapeLiteralBackReferences method has confusing while-loop logic with unclear variable names like backRefNum and backRefIndex. Some comments help explain the back-reference escaping logic, but they are lengthy blocks that interrupt flow. Action granularity is mostly reasonable, with one operation per line in most areas. Overall the code mixes clear sections with deeply cryptic regex manipulation, reducing maintainability.

Run 2

The code has several readability issues. The regex pattern RULE_PATTERN is extremely complex and undocumented, making the parsing logic nearly impossible to understand quickly. There is a random block of dead code inside the apply() method (variables startingPosition, endingPosition, travelDistance) that serves no purpose, disrupting flow and clarity. The escapeLiteralBackReferences method has extensive comments but the logic remains complex with non-obvious truncation behavior. The code uses long lines with multiple method calls chains. Nesting is moderate but the regex-based parser and error checking add significant cognitive load. Positive aspects: the class has clear intent (Kafka SSL principal mapping), reasonable grouping of methods (splitRules, parseRules, apply), and descriptive method names. The Rule inner class is well-encapsulated and has a clear toString. However, the overall readability suffers from excessive regex complexity, unclear variable naming in some cases (e.g., matcher.group indices), unexplained magic numbers in regex groups, and the dead code block. The action granularity is inconsistent - some lines combine too much logic. The code would benefit from extracting better-named helper methods and adding documentation explaining the mapping rule syntax.

Run 3

The code has some structural organization with helper methods and constants, but overall readability suffers from several issues. There is an obvious dead code block inside the 'apply' method that computes 'travelDistance' and then does nothing with it. The 'RULE_PATTERN' regex is extremely complex and poorly documented, making intent unclear. The 'escapeLiteralBackReferences' method is very hard to follow with multiple levels of nesting and unclear variable names like 'backRefNum' and 'backRefIndex'. The class has mixed responsibilities and the action granularity varies, with multiple operations packed into single lines in the parsing logic. The reading flow is disorganized—comments are redundant or overly verbose in places, and the natural progression of logic is interrupted by the dead code and complex regex handling. While the code is not completely unreadable, it requires significant effort to understand.

Run 1

Code Structure: Parsing, mapping, and replacement handling are sensibly separated into methods and a Rule class, but the unrelated travel-distance block disrupts cohesion. Nesting: Generally shallow, with moderate nesting in back-reference processing and rule formatting. Clarity of intent: Descriptive method names and explanatory comments help, but dense regexes, numbered capture groups, and abbreviated variables obscure details. Code length: Mostly proportionate to the functionality; the unused arithmetic block and some verbose comments add unnecessary length. Action granularity: Statements generally perform one action per line, although a few expressions combine several operations. Reading flow: The progression from parsing to applying rules is natural, but inconsistent indentation, long lines, extra whitespace, and the irrelevant block interrupt it.

Run 2

Code Structure: Parsing, mapping, and rule behavior are sensibly separated into methods and a nested class, but an unrelated travel-distance block disrupts apply(). Nesting: Mostly shallow, with moderate nesting in back-reference handling and toString(). Clarity of intent: Descriptive names and explanatory comments help, but dense regular expressions, numeric capture-group references, and the irrelevant block obscure intent. Code length: Generally appropriate, though unused distance calculations and verbose string-building add unnecessary length. Action granularity: Most statements perform one action per line; a few long expressions combine several operations and require extra effort to read. Reading flow: Method organization and early returns support natural progression, but inconsistent indentation, extra blank lines, and the inserted block interrupt it.

Run 3

Code Structure: Responsibilities are logically separated into splitting, parsing, mapping, and rule application, but the unrelated travel-distance block disrupts cohesion. Nesting: Generally shallow, with moderate nesting in back-reference handling and string formatting. Clarity of intent: Descriptive method and field names help, and comments explain replacement behavior; however, dense regexes, numeric capture-group references, and abbreviated variables require careful interpretation. Code length: Mostly proportionate to functionality, but unused travel-distance calculations and some verbose formatting add unnecessary length. Action granularity: Statements generally perform one action per line, although chained calls and long constructor arguments increase cognitive load. Reading flow: Method ordering and early returns support natural progression, but the poorly indented extraneous block, long lines, and inconsistent comment spacing interrupt it.