Sample

int-ab394b9db989-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines197

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.6030–1; higher is more readable
Dorn0.0730–1; higher is more readable
Mi0.0630–1; higher is more readable
LLOC103Logical lines; fewer is more readable
DeepSeek V4 Pro4.330–20; mean of three runs
GPT-6.1 Sol90–20; mean of three runs
BTTF0.1450–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))) {} else { 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()))) {} else { throw new IllegalArgumentException("Invalid rule: " + rule); } if (!((rule.length() != matcher.end()))) {} else { throw new IllegalArgumentException("Invalid rule: `" + rule + "`, unmatched substring: `" + rule.substring(matcher.end()) + "`"); } // empty rules are ignored if (!((matcher.group(1) != null))) { 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)))); } } else { result.add(new Rule()); } } return result; } public String getName(String distinguishedName) throws IOException { for (Rule r : rules) { String principalName = r.apply(distinguishedName); if (!((principalName != null))) {} else { 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))) {} else { return distinguishedName; } String result = null; final Matcher m = pattern.matcher(distinguishedName); if (!((m.matches()))) {} else { result = distinguishedName.replaceAll(pattern.pattern(), escapeLiteralBackReferences(replacement, m.groupCount())); } if (!((toLowerCase && result != null))) { if (toUpperCase && result != null) { result = result.toUpperCase(Locale.ENGLISH); } } else { result = result.toLowerCase(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))) {} else { 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")))) {} else { 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))) {} else { 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("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"); } } else { buf.append("DEFAULT"); } 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.8298.877−273.863
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.49−6.736

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

Score0.603

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.98−2.476
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.196.849+2.342
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.087+0.094

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

Score0.063
Score103
Run 1

The code is severely obfuscated by a pervasive 'if (!(condition)) {} else { ... }' pattern throughout, making even simple null checks and boolean branches confusing. The regex pattern RULE_PATTERN is complex and unexplained. Methods like escapeLiteralBackReferences contain convoluted logic with cryptic truncation behavior and confusing comments. Variable names are generally okay, but the unnatural conditional structure destroys reading flow and makes intent unclear. Nesting is deep in several places, and multiple actions sometimes occur on one line. While the code is somewhat organized into classes and methods, the execution paths are extremely hard to follow due to the inverted if-else blocks and lack of conventional structure. This would be very difficult to maintain or debug.

Run 2

The code is extremely difficult to read due to inverted conditionals throughout (e.g., `if (!(x)) {} else { ... }`), which obscures intent and breaks natural reading flow. The regex patterns are dense and unexplained, making them hard to understand. Formatting is inconsistent, with poorly indented nested conditionals and excessive line lengths. Multiple actions are packed into single lines (e.g., nested if/else in one line), and method names like `fromRules` add little semantic value. The `escapeLiteralBackReferences` method has convoluted logic and relies on external comments for comprehension. Nesting depth is shallow but the inverted logic makes control flow confusing. While the class is not overly long, the lack of clear structure, ambiguous conditional expressions, and poor formatting make it very hard to maintain or verify correctness.

Run 3

The code has several readability issues. The most significant problem is the pervasive use of inverted conditionals with empty if blocks and else blocks, such as 'if (!(condition)) {} else { ... }', which makes the logic extremely difficult to follow. This pattern appears throughout the code and forces readers to mentally invert conditions. The code also has excessive nesting in methods like escapeLiteralBackReferences and apply. The regular expression patterns are very dense with escape sequences and hard to understand at a glance. There are multiple actions on single lines, and the code contains unnecessary 'else' statements following 'if' blocks that already return. The method splitRules checks for null with 'if (!((sslPrincipalMappingRules == null))) {} else { ... }' which is extremely convoluted. While variable names are generally descriptive and the class structure is logically organized, the unusual conditional patterns, excessive nesting, and dense regex expressions make the code significantly harder to read than necessary. The code could be substantially improved by using standard conditional patterns, flattening nesting, and extracting complex logic into smaller methods.

Run 1

Code Structure: Responsibilities are reasonably separated into rule splitting, parsing, application, and back-reference handling. Nesting: Generally moderate, but inline nested conditionals and empty branches make control flow harder to follow. Clarity of intent: Descriptive method and field names help, while repeated negations, redundant parentheses, complex regexes, and numbered matcher groups obscure intent. Code length: Appropriate for the functionality overall, but empty conditional branches and verbose boolean expressions add unnecessary bulk. Action granularity: Most statements perform one action per line, though compressed conditional blocks undermine this consistency. Reading flow: The class progresses logically from construction to mapping and rule implementation, but inverted conditions repeatedly force readers to mentally reconstruct straightforward checks. Comments clarify the back-reference algorithm, partially offsetting the confusing syntax.

Run 2

Code Structure: Responsibilities are reasonably separated into rule splitting, parsing, application, and back-reference handling, with a cohesive Rule class. Nesting: Most methods have shallow nesting, but inline nested conditionals and empty branches make control flow harder to follow. Clarity of intent: Descriptive method and field names help, while repeated negations, redundant parentheses, complex regexes, and numbered capture groups obscure intent. Code length: Overall length is reasonable for the functionality, but empty if blocks and verbose conditional forms add unnecessary clutter. Action granularity: Most statements perform one action per line; several compressed conditional blocks violate this otherwise consistent style. Reading flow: Method organization and explanatory comments provide guidance, but inverted conditions and logic placed in else branches repeatedly interrupt natural reading.

Run 3

Code Structure: Responsibilities are logically separated into rule splitting, parsing, application, and back-reference handling. Nesting: Generally moderate, but compressed nested conditionals and empty branches make it harder to follow. Clarity of intent: Descriptive method and field names help, while repeated negations, redundant parentheses, opaque regexes, and numbered capture groups obscure intent. Code length: Reasonable for its responsibilities, though empty branches and verbose conditional forms add unnecessary clutter. Action granularity: Most statements perform one action per line, but several conditional blocks are packed onto single lines. Reading flow: Method organization is natural and comments explain complex replacement behavior, but inverted conditions force repeated mental simplification and disrupt otherwise straightforward control flow.