Sample

int-79b2c73d5123-I10

Remove about 40% of line-break groups while retaining structure

Matched original source

Lines122

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.4650–1; higher is more readable
Dorn0.0220–1; higher is more readable
Mi0.0040–1; higher is more readable
LLOC103Logical lines; fewer is more readable
DeepSeek V4 Pro7.330–20; mean of three runs
GPT-6.1 Sol90–20; mean of three runs
BTTF0.0460–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.122+48.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.721−7.081

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

Score0.465

Feature contributions

FeatureValueContribution
(log-odds)
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.221.967−5.737
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.123−3.319
Indentation frequencyHow rapidly indentation changes from line to line.113+3.171
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.222+2.777
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.113−2.172
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.121.821+1.293
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.112

Intercept 0.07 + feature contributions = -3.803 (log-odds).
Score = sigmoid(-3.803) = 0.022.

Score0.004
Score103
Run 1

The code has severe readability issues primarily due to poor formatting and structure. Multiple statements are crammed onto single lines (e.g., the package declaration, method definitions, and field assignments), making it difficult to follow the flow. The nesting is moderate but exacerbated by the lack of line breaks and indentation. The class is long and mixes parsing logic, rule application, and utility methods without clear separation. While the intent of mapping SSL principals is discernible, the regex patterns are complex and poorly explained. Action granularity is inconsistent—some lines contain multiple actions while others are properly spaced. The reading flow is disorganized; comments exist but are buried in unformatted code. Despite logical naming conventions and some clear method purposes, the overall presentation significantly hampers comprehension, warranting a low score.

Run 2

The code has significant readability issues. The package and import statements are compressed onto a single line, violating standard formatting conventions. The regex pattern RULE_PATTERN is complex and lacks explanatory comments, making it difficult to understand its purpose. There are multiple methods crammed onto the same line in several places, breaking the one-action-per-line principle. The Rule class has a critical bug where 'pattern' is used as both a String field and a Pattern object, and the toString() method incorrectly calls buf.append(pattern) which would trigger an infinite recursive call when pattern is itself a Pattern. Deep indentation and nested conditionals in parseRules and escapeLiteralBackReferences make the logic hard to follow. Variable names like 'm', 'r', and 'buf' are too abbreviated. The code mixes concerns of parsing, validation, and transformation without clear separation, and lacks proper spacing around operators and braces in several locations.

Run 3

The code suffers from poor readability due to extremely compressed formatting with multiple statements per line, inconsistent brace placement, and mixed indentation. The complex regex pattern (RULE_PATTERN) lacks explanation, making intent unclear. Methods like escapeLiteralBackReferences contain deeply nested logic with unclear truncation rules. While the class structure follows logical grouping (parsing, rule application), the execution is tangled. Variable names are reasonable but lost in dense formatting. The reading flow is severely disrupted by lines containing multiple method definitions and statements. Action granularity is violated throughout - multiple operations crammed onto single lines. Code length is acceptable but presentation destroys comprehension. Nesting in escapeLiteralBackReferences exceeds comfortable depth. Intent of regex patterns and back-reference handling requires significant effort to understand. Would benefit from standard formatting, expanded regex documentation, and method extraction.

Run 1

Code Structure: Responsibilities are logically separated into rule splitting, parsing, mapping, and a nested Rule class, but compressed formatting obscures boundaries. Nesting: Mostly moderate, with deeper loops and conditionals in back-reference handling and string rendering. Clarity of intent: Descriptive method names and explanatory comments help, but dense regexes, numbered capture groups, and abbreviated variables require careful interpretation. Code length: Reasonably proportionate to functionality, though lengthy comments and verbose string construction add reading overhead. Action granularity: Frequently poor; multiple declarations, assignments, statements, and even method boundaries share lines. Reading flow: Inconsistent indentation, inline braces, and crowded imports interrupt otherwise logical execution flow. The underlying design is understandable, but presentation significantly reduces readability.

Run 2

Code Structure: Responsibilities are logically separated into splitting, parsing, mapping, and a nested Rule class, but compressed formatting obscures method boundaries. Nesting: Generally moderate, although back-reference handling adds nested loops and conditionals. Clarity of intent: Descriptive method and field names and explanatory comments help, but complex regular expressions and numbered capture groups require careful interpretation. Code length: Mostly appropriate for the functionality, with some verbose string construction and comments; excessive compression reduces readability rather than meaningfully simplifying the code. Action granularity: Frequently poor, with multiple declarations, assignments, branches, and method boundaries sharing a line. Reading flow: Inconsistent indentation, inline braces, merged imports, and crowded statements repeatedly interrupt scanning. Overall, the underlying organization is reasonable, but presentation substantially undermines readability.

Run 3

Code Structure: Responsibilities are sensibly divided into splitting, parsing, mapping, and a nested Rule class, but compressed method boundaries obscure that organization. Nesting: Mostly moderate, though back-reference handling combines loops and conditionals that require careful tracking. Clarity of intent: Descriptive method and field names and explanatory comments help, but dense regexes, numbered capture groups, and abbreviated variables reduce clarity. Code length: Generally appropriate for the functionality, with little obvious unnecessary code; compression reduces physical length without improving readability. Action granularity: Frequently poor, with multiple declarations, assignments, branches, and method boundaries on the same line. Reading flow: Inconsistent indentation, inline braces, and crowded statements repeatedly interrupt scanning. Overall, coherent design and useful naming are undermined substantially by formatting.