Sample

int-be073948434a-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines197

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6230–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.330–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.1380–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(0x1)); } 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(0x1) != null) { result.add(new Rule()); } else if (matcher.group(0x2) != null) { result.add(new Rule(matcher.group(0x2), matcher.group(0x4), "L".equals(matcher.group(0x6)), "U".equals(matcher.group(0x6)))); } } 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 == 0x0) { return unescaped; } String value = unescaped; final Matcher backRefMatcher = BACK_REFERENCE_PATTERN.matcher(value); while (backRefMatcher.find()) { final String backRefNum = backRefMatcher.group(0x1); 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 >= 0xa) { backRefIndex /= 0xa; } if (backRefIndex > numCapturingGroups) { final StringBuilder sb = new StringBuilder(value.length() + 0x1); final int groupStart = backRefMatcher.start(0x1); sb.append(value, 0x0, groupStart - 0x1); sb.append("\\"); sb.append(value.substring(groupStart - 0x1)); 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.7750.89−255.779
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.489−6.734

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

Score0.623

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.975−2.475
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.196.829+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.077+0.19

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

Score0.053
Score103
Run 1

The code has clear organization and logical structure, with related components grouped together. However, readability is hindered by several issues: the use of hexadecimal literals (0x1, 0x2, 0x4, 0x6, 0xa) instead of decimal numbers is confusing; regex patterns are complex and not well-documented; method names like 'lookingAt' and 'matcher.end()' obscure intent; the 'escapeLiteralBackReferences' method has dense logic with deeply nested comments; action granularity is mixed with multiple operations per line; error messages lack context; and variables like 'm', 'r', 'buf' are too terse. Nesting is moderate but could be flatter. Overall, it's readable but requires domain knowledge to understand.

Run 2

The code follows a logical class structure and separates parsing from mapping, but readability suffers due to several factors. The regex patterns are complex and cryptic, especially RULE_PATTERN with multiple groups, making intent unclear without deep domain knowledge. Magic numbers and hex literals (0x1, 0x4, 0x6, 0xa) obscure array indices and numeric operations. The escapeLiteralBackReferences method is dense with nested logic and long comments that explain the complexity rather than simplifying it. While method names are clear and each method has a single responsibility, the parsing logic is difficult to trace. Nesting remains relatively flat, which helps, but the combination of regex-heavy code, unclear grouping, and excessive low-level operations reduces overall clarity. The code is concise but at the cost of transparency.

Run 3

The code has a clear overall structure with a top-level mapper class, inner Rule class, and exception type. However, readability suffers from several issues: (1) the regex pattern constants are extremely dense and use escaped delimiter syntax that is hard to parse visually; (2) hex literals like 0x1, 0xa, 0x0 are used instead of decimal 1, 10, 0, obscuring intent; (3) the escapeLiteralBackReferences method is difficult to follow with its loop, string manipulation, and numeric parsing; (4) some lines combine multiple concerns or rely on regex group indices that require counting parentheses; (5) while nesting is relatively shallow, the regex-driven logic makes the purpose ambiguous. Variable names are mostly descriptive, and comments are helpful in places, but the density of regex and hex tokens lowers the overall readability for a general developer unfamiliar with this exact pattern syntax.

Run 1

Code Structure: Well-organized methods separate splitting, parsing, mapping, and replacement handling; the nested Rule class encapsulates rule behavior. Nesting: Generally shallow, although back-reference processing and string formatting introduce moderate nesting. Clarity of intent: Descriptive method and field names help, but dense regular expressions, unexplained capture-group indices, hexadecimal literals for ordinary numbers, and abbreviated variables obscure details. Code length: Mostly appropriate, though repetitive initialization, formatting logic, and lengthy comments add some verbosity. Action granularity: Statements generally perform one action per line; a few compound expressions require extra effort to unpack. Reading flow: The progression from configuration parsing to rule application is natural, with early returns aiding comprehension. Inconsistent spacing, long lines, and the intricate back-reference algorithm interrupt otherwise clear flow.

Run 2

Code Structure: Responsibilities are logically separated into splitting, parsing, mapping, and an encapsulated Rule class. Nesting: Mostly shallow, though back-reference handling and rule formatting contain moderately nested branches. Clarity of intent: Descriptive method names and explanatory comments clarify the purpose, but dense regexes, positional capture groups, hexadecimal constants for ordinary numbers, and abbreviated variables obscure details. Code length: Generally proportionate to functionality, with some repetitive initialization and verbose string construction. Action granularity: Most statements perform one action, although regex matching and replacement expressions combine several operations. Reading flow: The progression from construction to parsing and application is natural; long lines, uneven comment formatting, and intricate back-reference manipulation interrupt otherwise consistent flow.

Run 3

Code Structure: Well organized into rule splitting, parsing, application, and an encapsulated Rule class. Nesting: Generally shallow, although back-reference handling introduces nested loops and conditionals. Clarity of intent: Descriptive method and field names communicate the mapping workflow, and comments explain tricky replacement behavior. However, dense regular expressions, unexplained capture-group indices, hexadecimal constants for ordinary numbers, and abbreviated variables obscure details. Code length: Mostly appropriate, with some verbosity in constructors, string building, and comments. Action granularity: Statements generally perform one action per line; a few long expressions combine several operations. Reading flow: The progression from construction through parsing to application is natural, but understanding regex parsing and back-reference escaping requires careful cross-referencing.