Giter Club home page Giter Club logo

Comments (5)

michal-trnka avatar michal-trnka commented on June 14, 2024 1

Awesome, thanks a lot for fixing that!

from jjwt.

lhazlewood avatar lhazlewood commented on June 14, 2024

Hi @michal-trnka! Thanks for the issue (and especially the test case!). This is very helpful.

For what it's worth, the concept of nested builders and using and() is documented throughout the project:

Also individual JwtBuilder claims methods work like this as well, they're just delegates to the nested claims() builder. For example:

@Override
public JwtBuilder issuer(String iss) {
    return claims().issuer(iss).and();
}

But I definitely understand how it may not be clear that one must call the and() method, resulting in this unexpected behavior.

So we'll use this issue to track the work to address this. There are two solutions:

  1. Change nested builder implementations to apply their changes immediately when add (and similar) methods are called.

    The challenge with this is that this is not typical builder behavior: most people expect builders to 'build' (do final completion work) when a build() method is called; (but for nested builders, the and() method is essentially the build method, it just also returns to the parent builder).

    So changing builder pattern semantics (instant change per method vs change-all-when-build-is-called) might cause confusion. It's probably worth thinking through the repercussions of changing this.

  2. Keep the existing "only apply changes when and() is called" and then just be super clear about this in documentation and JavaDoc so that it's consistent and people understand the repercussions.

I think my preference is the first solution if we can make this work easily and there are no negative side-effects. I'll have to do some testing.

Thanks again for the issue!

from jjwt.

michal-trnka avatar michal-trnka commented on June 14, 2024

Many thanks for the thorough explanation!

I have just again tested claims to be sure. It accepts the following code snipped. I guess this is what made me confused most.

builder.claims().add("my-claim", "my-value");

I'd prefer option # 2. However, adding it to JavaDoc would make the behavior more transparent and would work for me too.

from jjwt.

lhazlewood avatar lhazlewood commented on June 14, 2024

@michal-trnka after looking at the code, I went with the first option in PR #917 and it worked out well - no surprises or 'penalties' to work around.

There was partly a strong reason to apply changes immediately, not the least of which is that it didn't 'hurt' anything, but also it avoids problems with method chains like:

.header().add("foo", "bar");
// sometime later:
.header().empty().critical()...

If we didn't apply changes immediately when .empty() is called, we'd have to create internal 'stack' of sorts to track changes across method invocations before the .and() method is finally called. It was much easier to avoid that and be consistent across all mutation/change methods.

from jjwt.

lhazlewood avatar lhazlewood commented on June 14, 2024

This is now released in 0.12.5. @michal-trnka Thank you for reporting the issue!

from jjwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.