GithubHelp home page GithubHelp logo

Comments (5)

gissuebot avatar gissuebot commented on May 15, 2024

From limpbizkit on February 27, 2007 21:28:01

I imagine there are scenarios where null is reasonable. Suppose you have a service that checks permissions
against a Guice-provided user. No user might imply non-interactive use, such as by a batch process:

public class AccountService {
  @Inject User user;
  @Inject Customer customer;
  public Account getAccount() {
    Account account = lookupCustomerAccount(customer.getId());
    if(user != null && !account.isViewableBy(user)) {
      throw new InsufficientPermissionsException();
    }
    return account;
  }
}

IMHO, this particular situation doesn't really lend itself to a null-object pattern.

But I do think injecting null is something you'd want to do very rarely. So perhaps instead of banning it
outright, we should make it on-by-default and users could opt-out (like required=false):
  @Inject(nullable=true) User user;

from guice.

gissuebot avatar gissuebot commented on May 15, 2024

From kevinb9n on February 28, 2007 11:17:34

I don't see why a null-object pattern wouldn't work here.  But actually in this case
you don't really want a User at all, you want a ThingThatDecidesPermissions or
PermissionProfile or Authorizations or some such object, and that should never be null.

Null is stinky...

from guice.

gissuebot avatar gissuebot commented on May 15, 2024

From crazyboblee on February 28, 2007 12:24:17

Or an anonymous/guest user. Down with null.

from guice.

gissuebot avatar gissuebot commented on May 15, 2024

From crazyboblee on February 28, 2007 14:45:08

(No comment was entered for this change.)

Labels: 1.0RC3

from guice.

gissuebot avatar gissuebot commented on May 15, 2024

From kevinb9n on March 01, 2007 02:58:35

Fixed with revision 248 .

Status: Fixed

from guice.

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.