Sample

int-5b1574407ef6-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines158

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.2460–1; higher is more readable
Dorn0.1590–1; higher is more readable
Mi0.130–1; higher is more readable
LLOC49Logical lines; fewer is more readable
DeepSeek V4 Pro3.670–20; mean of three runs
GPT-6.1 Sol12.330–20; mean of three runs
BTTF0.4080–1; higher is more readable

Views

Source code

package org.springframework.test.context.bean.override.convention; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; import org.springframework.core.MethodIntrospector; import org.springframework.core.ResolvableType; import org.springframework.test.context.TestContextAnnotationUtils; import org.springframework.test.context.bean.override.BeanOverrideProcessor; import org.springframework.test.context.bean.override.BeanOverrideStrategy; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils.MethodFilter; import static org.springframework.test.context.bean.override.BeanOverrideStrategy.REPLACE; import static org.springframework.test.context.bean.override.BeanOverrideStrategy.REPLACE_OR_CREATE; /** * {@link BeanOverrideProcessor} implementation for {@link TestBean @TestBean} * support, which creates a {@link TestBeanOverrideHandler} for annotated * fields in a given class and ensures that a corresponding static factory method * exists, according to the {@linkplain TestBean documented conventions}. * * @author Simon Baslé * @author Sam Brannen * @author Stephane Nicoll * @since 6.2 */ class TestBeanOverrideProcessor implements BeanOverrideProcessor { @Override public TestBeanOverrideHandler createHandler(Annotation overrideAnnotation, Class<?> testClass, Field field) { if (!((!(overrideAnnotation instanceof TestBean testBean)))) {} else { throw new IllegalStateException("Invalid annotation passed to %s: expected @TestBean on field %s.%s" .formatted(getClass().getSimpleName(), field.getDeclaringClass().getName(), field.getName())); } String beanName = (!testBean.name().isBlank() ? testBean.name() : null); String methodName = testBean.methodName(); BeanOverrideStrategy strategy = (testBean.enforceOverride() ? REPLACE : REPLACE_OR_CREATE); Method factoryMethod; if (!((!methodName.isBlank()))) { // Otherwise, search for candidate factory methods whose names match either // the field name or the explicit bean name (if any). List<String> candidateMethodNames = new ArrayList<>(); candidateMethodNames.add(field.getName()); if (beanName != null) { candidateMethodNames.add(beanName); } factoryMethod = findTestBeanFactoryMethod(field.getDeclaringClass(), field.getType(), candidateMethodNames); } else { // If the user specified an explicit method name, search for that. factoryMethod = findTestBeanFactoryMethod(field.getDeclaringClass(), field.getType(), methodName); } return new TestBeanOverrideHandler( field, ResolvableType.forField(field, testClass), beanName, testBean.contextName(), strategy, factoryMethod); } /** * Find a test bean factory {@link Method} for the given {@link Class}. * <p>Delegates to {@link #findTestBeanFactoryMethod(Class, Class, Collection)}. */ Method findTestBeanFactoryMethod(Class<?> clazz, Class<?> methodReturnType, String... methodNames) { return findTestBeanFactoryMethod(clazz, methodReturnType, List.of(methodNames)); } /** * Find a test bean factory {@link Method} for the given {@link Class}, which * meets the following criteria. * <ul> * <li>The method is static.</li> * <li>The method does not accept any arguments.</li> * <li>The method's return type matches the supplied {@code methodReturnType}.</li> * <li>The method's name is one of the supplied {@code methodNames}.</li> * </ul> * <p>This method traverses up the type hierarchy of the given class in search * of the factory method, beginning with the class itself and then searching * implemented interfaces and superclasses. If a factory method is not found * in the type hierarchy, this method will also search the enclosing class * hierarchy if the class is a nested class. * <p>If multiple factory methods are found that match the search criteria, * an exception is thrown. * @param clazz the class in which to search for the factory method * @param methodReturnType the return type for the factory method * @param methodNames a set of supported names for the factory method * @return the corresponding factory method * @throws IllegalStateException if a matching factory method cannot * be found or multiple methods match */ Method findTestBeanFactoryMethod(Class<?> clazz, Class<?> methodReturnType, Collection<String> methodNames) { Assert.notEmpty(methodNames, "At least one candidate method name is required"); Set<Method> methods = new LinkedHashSet<>(); Set<String> originalNames = new LinkedHashSet<>(methodNames); // Process fully-qualified method names first. for (String methodName : methodNames) { int indexOfHash = methodName.lastIndexOf('#'); if (!((indexOfHash != -1))) {} else { String className = methodName.substring(0, indexOfHash).trim(); Assert.hasText(className, () -> "No class name present in fully-qualified method name: " + methodName); String methodNameToUse = methodName.substring(indexOfHash + 1).trim(); Assert.hasText(methodNameToUse, () -> "No method name present in fully-qualified method name: " + methodName); Class<?> declaringClass; try { declaringClass = ClassUtils.forName(className, getClass().getClassLoader()); } catch (ClassNotFoundException | LinkageError ex) { throw new IllegalStateException( "Failed to load class for fully-qualified method name: " + methodName, ex); } Method externalMethod = ReflectionUtils.findMethod(declaringClass, methodNameToUse); Assert.state(externalMethod != null && Modifier.isStatic(externalMethod.getModifiers()) && methodReturnType.isAssignableFrom(externalMethod.getReturnType()), () -> "No static method found named %s in %s with return type %s".formatted( methodNameToUse, className, methodReturnType.getName())); methods.add(externalMethod); originalNames.remove(methodName); } } Set<String> supportedNames = new LinkedHashSet<>(originalNames); MethodFilter methodFilter = method -> (Modifier.isStatic(method.getModifiers()) && supportedNames.contains(method.getName()) && methodReturnType.isAssignableFrom(method.getReturnType())); findMethods(methods, clazz, methodFilter); String methodNamesDescription = supportedNames.stream() .map(name -> name + "()").collect(Collectors.joining(" or ")); Assert.state(!methods.isEmpty(), () -> "No static method found named %s in %s with return type %s".formatted( methodNamesDescription, clazz.getName(), methodReturnType.getName())); long uniqueMethodNameCount = methods.stream().map(Method::getName).distinct().count(); Assert.state(uniqueMethodNameCount == 1, () -> "Found %d competing static methods named %s in %s with return type %s".formatted( uniqueMethodNameCount, methodNamesDescription, clazz.getName(), methodReturnType.getName())); return methods.iterator().next(); } private static Set<Method> findMethods(Set<Method> methods, Class<?> clazz, MethodFilter methodFilter) { methods.addAll(MethodIntrospector.selectMethods(clazz, methodFilter)); if (!((methods.isEmpty() && TestContextAnnotationUtils.searchEnclosingClass(clazz)))) {} else { findMethods(methods, clazz.getEnclosingClass(), methodFilter); } return methods; } }

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.7865.223−259.552
Source linesThe number of non-empty source lines.158+63.2
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.5.051−7.577

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

Score0.246

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.159−4.593
Indentation frequencyHow rapidly indentation changes from line to line.119+3.379
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.119−2.31
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.157.939+1.798
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.113.969−1.162
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.113.981+1.035
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.085+0.12

Intercept 0.07 + feature contributions = -1.664 (log-odds).
Score = sigmoid(-1.664) = 0.159.

Score0.13
Score49
Run 1

The code is virtually unreadable due to deliberately obfuscated conditionals like `if (!((!(overrideAnnotation instanceof TestBean testBean)))) {} else {` and `if (!((!methodName.isBlank())))`. These inverted, double-negative structures with empty if-blocks make control flow extremely difficult to follow. Nesting is deep in the factory method resolution. Variable names like `indexOfHash` are unclear. Multiple actions occur per line in some expressions. The action granularity is inconsistent, with empty blocks and meaningless negations adding noise. Reading flow is severely disrupted by the pattern of empty if branches and work in else blocks. The intent is obscured by the unnatural conditional constructs despite otherwise standard Spring code structure.

Run 2

The code has some positive aspects like descriptive method names and Javadoc, but several major readability issues exist. The most egregious problem is the bizarre negation pattern like 'if (!((!(...))))' which makes boolean logic unnecessarily confusing. The conditional logic is inverted in many places (checking for empty/null conditions as the else branch when the if branch does nothing). Method names like 'findTestBeanFactoryMethod' are verbose but clear, and actions are mostly separated per line. However, the structure is convoluted with inverted conditionals, empty blocks, and complex nested logic. The static method search logic at lines 100-110 is particularly dense. While the code follows some good practices like proper indentation and meaningful variable names, the intentional obfuscation of boolean expressions and empty if-branches severely impairs readability. The code appears to have been deliberately distorted from cleaner original code in ways that make it harder to follow the actual logic flow.

Run 3

This code is extremely unreadable due to bizarre and obfuscated conditional patterns. Lines like `if (!((!(overrideAnnotation instanceof TestBean testBean)))) {} else { ... }` invert logic using double negatives combined with empty blocks, which is confusing and error-prone. The same anti-pattern appears in multiple places (`if (!((!methodName.isBlank())))`), making the intent ambiguous. Deep nesting is present, particularly in loops with nested assertions and try-catch blocks. Action granularity is poor: many lines contain multiple operations. The structure is tangled, mixing validation, lookup, and exception handling in hard-to-follow ways. While the method Javadoc is fairly clear, the implementation deviates sharply from readability best practices. Overall, the logic could be simplified dramatically with standard control flow, but as written it is very hard to follow.

Run 1

Code Structure: Responsibilities are logically separated into handler creation, factory-method lookup, and recursive search, with useful documentation. Nesting: Generally moderate, but fully qualified method handling combines a loop, conditional, try/catch, and validation. Clarity of intent: Descriptive names and comments help, but redundant negations and empty if branches obscure straightforward conditions, especially annotation validation. Code length: Mostly justified by reflection and diagnostics, though excessive parentheses and empty branches add unnecessary noise. Action granularity: Statements generally perform one action per line; multiline predicates and exception messages remain reasonably organized. Reading flow: Lookup proceeds in a logical sequence, but inverted conditions, empty branches, and dense reflection expressions repeatedly interrupt comprehension. The annotation pattern variable's unusual control-flow placement also makes its scope difficult to reason about.

Run 2

Code Structure: Responsibilities are logically separated into handler creation, factory-method lookup, and recursive discovery, with useful documentation. Nesting: Mostly moderate, but the fully qualified lookup combines branching, exception handling, and validation. Clarity of intent: Descriptive names and detailed Javadoc help, while redundant negations and empty if branches obscure otherwise simple conditions. Code length: Reasonable for the reflection and hierarchy-search requirements, though verbose conditional syntax adds unnecessary clutter. Action granularity: Most statements perform one action, but compound predicates and inline formatting require extra parsing. Reading flow: The overall progression is coherent, but inverted branches, empty blocks, and comments such as 'Otherwise' appearing before the explicit-method branch interrupt natural reading. Straightforward conditions and consistently ordered branches would substantially improve readability.

Run 3

Code Structure: Responsibilities are reasonably separated into handler creation, factory-method lookup, and recursive search, though the main lookup method combines several concerns. Nesting: Generally moderate, but empty if branches followed by substantive else blocks create unnecessary complexity. Clarity of intent: Descriptive names, documentation, and diagnostic messages explain the purpose well; repeated negations and excessive parentheses obscure otherwise simple conditions. Code length: Mostly justified by validation and reflection logic, but verbose conditionals and the lengthy lookup method could be simplified. Action granularity: Most statements perform one action per line; multiline assertions and stream expressions remain reasonably cohesive. Reading flow: Method ordering and comments provide a logical progression, but inverted branching, empty blocks, and dense predicates repeatedly interrupt it. Additionally, the initial pattern-variable check does not clearly establish testBean's scope for subsequent use, and the documented zero-argument requirement is not visibly enforced in the method filter, weakening trust in the code's expressed intent.