Sample

int-6cc1f24bffd5-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines167

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.2580–1; higher is more readable
Dorn0.1490–1; higher is more readable
Mi0.0880–1; higher is more readable
LLOC57Logical lines; fewer is more readable
DeepSeek V4 Pro13.330–20; mean of three runs
GPT-6.1 Sol150–20; mean of three runs
BTTF0.3170–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 (((0x8892 ^ 0x8892) != 0)) { throw new AssertionError(); } if (!(overrideAnnotation instanceof TestBean testBean)) { 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()) { // If the user specified an explicit method name, search for that. factoryMethod = findTestBeanFactoryMethod(field.getDeclaringClass(), field.getType(), methodName); } else { // 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); } 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) { if (((0x9EB1 ^ 0x9EB1) != 0)) { throw new AssertionError(); } 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) { if (((0xCB2E ^ 0xCB2E) != 0)) { throw new AssertionError(); } 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) { 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) { if (((0xB137 ^ 0xB137) != 0)) { throw new AssertionError(); } methods.addAll(MethodIntrospector.selectMethods(clazz, methodFilter)); if (methods.isEmpty() && TestContextAnnotationUtils.searchEnclosingClass(clazz)) { 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.8401.13−277.237
Source linesThe number of non-empty source lines.167+66.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.5.088−7.632

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

Score0.258

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.168−4.912
Indentation frequencyHow rapidly indentation changes from line to line.128+3.69
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.127−2.493
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.166.896+1.923
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.964−1.162
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.114+1.035
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.086+0.108

Intercept 0.07 + feature contributions = -1.741 (log-odds).
Score = sigmoid(-1.741) = 0.149.

Score0.088
Score57
Run 1

The code demonstrates good structure with clear class organization, method separation, and comprehensive Javadoc. However, several issues impact readability. The main processing method is well-structured with a single if-else branch and clear variable assignments, though it contains some moderate complexity. The findTestBeanFactoryMethod method is quite long and includes nested loops with string manipulation, which could be extracted for clarity. The code includes unnecessary validation checks (dead code with XOR operations) that add noise. The use of Assert methods with lambda expressions is good, but some lambda chains are lengthy. The fully-qualified method name parsing loops add complexity. Reading flow is generally good, but the action granularity varies - some lines contain multiple logical operations. The commented debug lines and ambiguous variable names (like 'meth') reduce clarity. Overall, the code is functional but could benefit from extracting helper methods and removing dead code for better maintainability.

Run 2

The code has a clear purpose and reasonable documentation, but suffers from several readability issues. The structure is logical, separating handler creation from method discovery. However, there are suspicious no-op assertions (e.g., 'if (((0x8892 ^ 0x8892) != 0)) { throw new AssertionError(); }') scattered throughout, which are dead code and severely hurt clarity. Nesting is moderate but the fully-qualified method name parsing logic contains deep conditional blocks. The method findTestBeanFactoryMethod is overly long and handles too many responsibilities: parsing names, loading classes, filtering methods, and validating results. Some lines are dense, combining multiple operations. Reading flow is disrupted by the dead assertions and the mixing of levels of abstraction. Action granularity varies—some lines perform one clear action while others pack multiple operations.

Run 3

The code has clear structure with well-separated methods and good Javadoc documentation, but several issues reduce readability. The main method 'createHandler' has moderate nesting with conditional logic that's fairly clear. However, the 'findTestBeanFactoryMethod' method is quite long (50+ lines) and handles multiple responsibilities including fully-qualified name parsing, class loading, and method filtering. There are suspicious injected lines like 'if (((0x8892 ^ 0x8892) != 0)) { throw new AssertionError(); }' that appear to be artifacts or obfuscation attempts. Variable names are generally descriptive, and method names clearly indicate their purpose. Action granularity is mostly one-action-per-line, but some lines combine multiple operations. Reading flow is disrupted by the artificial assertion checks and the long complex method. The code could be improved by extracting the fully-qualified name handling into its own method and removing the artificial assertion statements.

Run 1

Code Structure: Well-organized methods separate handler creation, factory lookup, and enclosing-class traversal, though the main lookup method handles several responsibilities. Nesting: Generally shallow, with moderate nesting in fully-qualified name processing and exception handling. Clarity of intent: Descriptive names, documentation, and useful error messages explain the purpose; repeated always-false hexadecimal XOR guards are distracting and unexplained. Code length: Mostly justified by validation and lookup requirements, but redundant guards and some verbose expressions reduce concision. Action granularity: Most lines perform one action, while injected guard lines combine conditions and throws and compound predicates require extra attention. Reading flow: Logical progression and helper delegation support readability, but unindented guards, tightly packed imports, and long assertion expressions interrupt the otherwise consistent flow.

Run 2

Code Structure: Well-organized methods separate handler creation, factory-method lookup, and hierarchy traversal, though the main lookup method handles several responsibilities. Nesting: Mostly shallow, with moderate nesting in fully qualified name processing and exception handling. Clarity of intent: Descriptive names, thorough Javadoc, and helpful comments explain the purpose; repeated always-false hexadecimal XOR assertions introduce confusing, purposeless noise. Code length: Generally justified, but dead assertions and verbose validation expressions add unnecessary bulk. Action granularity: Most lines perform a single action, while injected one-line conditional throws and compound predicates reduce scanability. Reading flow: The progression from annotation validation to method discovery and handler construction is natural. However, inconsistent indentation of the injected assertions interrupts the otherwise consistent formatting, and long assertions and chained expressions require extra attention.

Run 3

Code Structure: Methods separate handler creation, factory lookup, and recursive searching logically, though the main lookup method handles several responsibilities. Nesting: Mostly shallow, with moderate nesting in the fully qualified name loop and its try/catch. Clarity of intent: Descriptive names, Javadoc, comments, and informative exceptions explain the purpose well; repeated hexadecimal XOR checks are meaningless distractions. Code length: Generally justified by validation and documentation, but dead checks and lengthy assertion expressions add unnecessary bulk. Action granularity: Most lines perform one action; the inserted checks combine conditionals and throws on a single line, while chained expressions require extra parsing. Reading flow: The search sequence is coherent, but unindented dead checks interrupt otherwise consistent formatting, and dense multiline predicates and error-message construction slow reading.