Skip to content

Fix Intermittent Gateway Test Failures Due to Bytecode Reordering#4014

Closed
Kcruz28 wants to merge 1 commit intospring-cloud:mainfrom
Kcruz28:fix-noHiddenHttpMethodFilter
Closed

Fix Intermittent Gateway Test Failures Due to Bytecode Reordering#4014
Kcruz28 wants to merge 1 commit intospring-cloud:mainfrom
Kcruz28:fix-noHiddenHttpMethodFilter

Conversation

@Kcruz28
Copy link
Contributor

@Kcruz28 Kcruz28 commented Dec 2, 2025

Problem

Found this while running NonDex on the test suite. When running the test with certain bytecode reordering patterns,
GatewayAutoConfigurationTests.noTokenRelayFilter fails intermittently because the test setup relies on
implicit Spring Application initialization order.

The issue occurs because:

  1. The test uses SpringApplication.run(...) with command-line arguments
  2. Properties pass through Spring's argument parsing pipeline, which depends on classloader initialization order
  3. Due to bytecode reordering, property application becomes non-deterministic
  4. Sometimes the token-relay filter is disabled as intended, sometimes it isn't
  5. This results in inconsistent test behavior that breaks under NonDex shuffling

Solution

Replace SpringApplication.run(...) with Spring Boot's ReactiveWebApplicationContextRunner,
which provides explicit control over auto-configurations and property injection.

  • Removes implicit SpringApplication.run() initialization with command-line arguments
  • Adds explicit .withConfiguration() to declare which auto-configurations are active
  • Adds .withPropertyValues() to set properties deterministically (not via argument parsing)
  • Changes assertion from exception-based to direct bean presence check

Why This Matters

This type of issue indicates a hidden dependency on bytecode ordering within the test setup.
By fixing it, we:

  • Ensure consistent test behavior across different execution environments
  • Prevent intermittent CI/CD failures that are hard to debug
  • Align with the established pattern used by all other tests in the suite (nettyHttpClientDefaults, nettyHttpClientConfigured, tokenRelayBeansAreCreated, etc.)
  • Make the test more maintainable—explicit setup is easier to understand than implicit SpringApplication initialization

Files Changed

  • GatewayAutoConfigurationTests.java
  • Updated noTokenRelayFilter() test method to use ReactiveWebApplicationContextRunner

…ationContextRunner and consistent formatting
@spencergibb spencergibb closed this Dec 2, 2025
@spencergibb
Copy link
Member

I don't think we need any fixes found by nondex thank you. It's just noise and we aren't having any problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants