Skip to content

NoClassDefFound with version 7.1.0 #19317

Closed

Description

@bursauxa

Description

Context: we are using spring-security-cypto as a standalone library.

Starting with version 7.1.0, BCryptPasswordEncoder.matches(...) throws java.lang.NoClassDefFoundError: org/springframework/util/StringUtils.

This is consistent with the published pom.xml (Maven Central) that does not list spring-core as a dependency.

The gradle manifest declares it as optional, so it makes sense that it would not be part of the POM.

Cause for change

In version 7.0.x, the implementation for AbstractValidatingPasswordEncoder did not make use of spring-core, so the issue was not apparent.

7.0.x branch:

        if (encodedPassword == null || encodedPassword.length() == 0) {
            return false;
        }
        return upgradeEncodingNonNull(encodedPassword);

main branch:

import org.springframework.util.StringUtils;
...
        if (!StringUtils.hasLength(rawPassword) || !StringUtils.hasLength(encodedPassword)) {
            return false;
        }
        return matchesNonNull(rawPassword.toString(), encodedPassword);

Samples

A runnable sample on JDoodle does not exhibit the behavior, as that seems to be using Gradle under the hood, which might be able to resolve the optional dependency. This is also probably why the project's unit tests pass.

However, a runnable sample on Scastie does exhibit the behavior. It is Scala, but the one-liner code is not important, what is important is that it only uses the pom declaration.

Activity

  1. added
    status: waiting-for-triage
    type: bug
    on Jun 10, 2026
  2. aka-mgillette commented on Jun 11, 2026

    @aka-mgillette

    I'm seeing this in AbstractValidatingPasswordEncoder instead of AbstractPasswordEncoder - maybe a typo? Looking forward to any resolution as well.

  3. bursauxa commented on Jun 12, 2026

    @bursauxa
    Author

    You are correct @aka-mgillette - I updated my post.

    (the quoted code was from the correct place!)

  4. mschorsch commented on Jun 18, 2026

    @mschorsch

    +1

  5. FlyingSheepOnSailfish commented on Jun 26, 2026

    @FlyingSheepOnSailfish

    We ran into this issue today.
    A quick peek in the code of AbstractValidatingPasswordEncoder 7.1.0 shows imports of 2 classes from spring-core

    • org.springframework.lang.Contract
    • org.springframework.util.StringUtils

    Maven gives no indication that spring-crypto has any dependencies.

    The online documentation for Spring Security starts with:
    "The Spring Security Crypto module provides support for symmetric encryption, key generation, and password encoding. The code is distributed as part of the core module but has no dependencies on any other Spring Security (or Spring) code."

  6. alexsuter commented on Jul 21, 2026

    @alexsuter

    +1

  7. kpur-sbab commented on Aug 6, 2026

    @kpur-sbab

    +1

  8. seonwooj0810 commented on Aug 12, 2026

    @seonwooj0810
    Contributor

    Thanks for the detailed report and repro (@bursauxa) and the confirmations (@aka-mgillette, @mschorsch, @FlyingSheepOnSailfish, @alexsuter, @kpur-sbab) — this looks like a genuine regression introduced when AbstractValidatingPasswordEncoder started using org.springframework.util.StringUtils/org.springframework.lang.Contract (spring-core) without spring-core becoming a non-optional dependency of spring-security-crypto's published POM.

    Since the crypto module's docs explicitly promise "no dependencies on any other Spring Security (or Spring) code," there seem to be two possible fix directions:

    1. Remove the new spring-core imports from AbstractValidatingPasswordEncoder (inline the equivalent null/empty checks), preserving the documented zero-dependency contract.
    2. Make spring-core a required (non-optional) dependency in the Gradle build so the published POM declares it.

    Direction 1 seems more in line with the documented contract and has no downstream footprint, but I wanted to check preference before submitting a PR — happy to implement whichever direction you'd prefer (or hold off if this is already being tracked internally).

  9. bursauxa commented on Aug 12, 2026

    @bursauxa
    Author

    I think your earlier PR is completely fine @seonwooj0810

  10. alexsuter commented on Aug 19, 2026

    @alexsuter

    @seonwooj0810 It would be nice if spring crypto has no additional dependencies.

  11. seonwooj0810 commented on Sep 1, 2026

    @seonwooj0810
    Contributor

    @alexsuter That's the direction I went with — #19341 does exactly that.

    It removes the two org.springframework.util.StringUtils#hasLength calls that AbstractValidatingPasswordEncoder picked up in 7.1.0 and replaces them with plain JDK null/empty checks — a three-line diff in that one file, marked Closes gh-19317. So spring-security-crypto gains no dependency and keeps the documented "no dependencies on any other Spring Security (or Spring) code" contract. That's direction 1 of the two I listed above, rather than promoting spring-core to a required dependency in the published POM.

    CI is green on it; it's waiting on maintainer review.

  12. added 2 commits that reference this issue on Sep 10, 2026
    8d0998f
    7cc2077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: waiting-for-triagetype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions