Example usage for java.lang NullPointerException NullPointerException

List of usage examples for java.lang NullPointerException NullPointerException

Introduction

In this page you can find the example usage for java.lang NullPointerException NullPointerException.

Prototype

public NullPointerException(String s) 

Source Link

Document

Constructs a NullPointerException with the specified detail message.

Usage

From source file:cz.muni.fi.pa165.deliveryservice.dao.jpa.JPACourierDAO.java

@Override
public void deleteCourier(Courier courier) {
    if (courier == null) {
        throw new NullPointerException("Courier argument can't be null");
    }/*  ww  w.  java 2  s.c om*/

    if (courier.getId() == null) {
        throw new IllegalStateException("Trying to delete courier with no id assigned");
    }

    Courier toRemove = em.find(Courier.class, courier.getId());

    em.remove(toRemove);
}

From source file:com.bigdata.rockstor.console.RockStorSender.java

private static HttpRequestBase buildHttpRequest(HttpReq req)
        throws UnsupportedEncodingException, URISyntaxException {

    HttpRequestBase request = null;/*from  ww w.j a va  2  s  .c  o  m*/
    if ("GET".equals(req.getMethod())) {
        request = new HttpGet();
    } else if ("PUT".equals(req.getMethod())) {
        request = new HttpPut();
        if (req.getBody() != null && req.getBody().length() > 0)
            ((HttpPut) request).setEntity(new StringEntity(req.getBody()));
    } else if ("DELETE".equals(req.getMethod())) {
        request = new HttpDelete();
    } else if ("HEAD".equals(req.getMethod())) {
        request = new HttpHead();
    } else {
        throw new NullPointerException("Unknown HTTP Method : " + req.getMethod());
    }

    request.setURI(new URI(req.getUrl()));

    if (req.getHead() != null) {
        for (Map.Entry<String, String> e : req.getHead().entrySet()) {
            if ("PUT".equals(req.getMethod()) && e.getKey().equals("Content-Length"))
                continue;
            request.setHeader(e.getKey(), e.getValue());
        }
    }

    return request;
}

From source file:Main.java

/**
 * Construct a file from the set of name elements.
 *
 * @param directory the parent directory
 * @param names     the name elements//from   ww  w  . j  a  va 2  s. com
 * @return the file
 * @since 2.1
 */
public static File getFile(File directory, String... names) {
    if (directory == null) {
        throw new NullPointerException("directorydirectory must not be null");
    }
    if (names == null) {
        throw new NullPointerException("names must not be null");
    }
    File file = directory;
    for (String name : names) {
        file = new File(file, name);
    }
    return file;
}

From source file:io.github.howiefh.jeews.modules.sys.controller.LoginCotroller.java

@RequestMapping(value = "", method = RequestMethod.POST)
public Map<String, Object> login(@RequestBody User u) {
    String username = u.getUsername();
    String password = u.getPassword();
    if (username == null) {
        throw new NullPointerException("????");
    }/*  w ww . jav  a  2 s  .  co  m*/
    User user = userService.findByName(username);

    if (user == null) {
        throw new UnknownAccountException("??");// ??
    }

    if (Boolean.TRUE.equals(user.getLocked())) {
        throw new LockedAccountException("???"); // ???
    }

    if (!userService.passwordsMatch(user, password)) {
        throw new IncorrectCredentialsException("????");
    }

    JWTSigner signer = new JWTSigner(secret);
    Options options = new Options();
    // 7 * 24 * 60 * 60 = 604800
    options.setExpirySeconds(604800);
    Map<String, Object> claims = new HashMap<String, Object>();
    RolePermission rolePermission = user.new RolePermission();
    claims.put("perms", rolePermission.getPermissionSet());
    claims.put("iss", user.getUsername());
    String token = signer.sign(claims, options);

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("access_token", token);
    Map<String, Object> userMap = new HashMap<String, Object>();
    userMap.put("id", user.getId());
    userMap.put("username", user.getUsername());
    userMap.put("perms", rolePermission.getPermissionSet());
    userMap.put("roles", rolePermission.getRoleSet());
    map.put("user", userMap);
    return map;
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.permissions.PublishByRolePermission.java

public PublishByRolePermission(String roleName, RoleLevel roleLevel) {
    super(NAMESPACE + roleName);

    if (roleName == null) {
        throw new NullPointerException("role may not be null.");
    }//  w  w  w .j a  va 2 s  .co m
    if (roleLevel == null) {
        throw new NullPointerException("roleLevel may not be null.");
    }

    this.roleName = roleName;
    this.roleLevel = roleLevel;
}

From source file:com.gdo.util.XmlWriter.java

/**
 * Creates a new XML writer.//from   w w  w . j  a v  a 2  s  . c  o m
 * 
 * @param writer
 *            underlying writer.
 * @param indent
 *            starting indentation level.
 * @param encoding
 *            character encoding used.
 */
public XmlWriter(Writer writer, int indent, String encoding) {
    if (writer == null) {
        throw new NullPointerException("Cannot create a XML writer without an underlying writer");
    }
    if (StringUtils.isEmpty(encoding)) {
        throw new NullPointerException("Cannot create a XML writer without charset encoding");
    }
    _writer = writer;
    _encoding = encoding;
    _indent = indent;
}

From source file:edu.cornell.mannlib.vedit.util.OperationUtils.java

/**
 * Takes a bean and clones it using reflection. Any fields without standard
 * getter/setter methods will not be copied.
 *//*  w ww. jav a2s.  co m*/
public static Object cloneBean(Object bean) {
    if (bean == null) {
        throw new NullPointerException("bean may not be null.");
    }
    return cloneBean(bean, bean.getClass(), bean.getClass());
}

From source file:org.zalando.maven.plugins.swagger.parsing.ParserTest.java

/**
 * Same code as in the parser itself to find out what is wrong with the swagger.yaml file.
 *//*from www .j av  a  2  s.c  om*/
@Test
public void yamlParse() throws JsonProcessingException, IOException {
    JsonNode rootNode = null;
    ObjectMapper objectMapper = Yaml.mapper();
    rootNode = objectMapper.readTree(getClass().getResourceAsStream("/swagger.yaml"));

    JsonNode swaggerNode = rootNode.get("swagger");
    if (swaggerNode == null) {

        throw new NullPointerException("You failed!");
    }

    swagger = objectMapper.convertValue(rootNode, Swagger.class);
    Assertions.assertThat(swagger).isNotNull();
}

From source file:com.google.nigori.common.Revision.java

/**
 * This methods exists as a convenience for when writing tests, use is not encouraged in general.
 * @param revision//from w w w.j av a 2  s  .  co  m
 * @throws UnsupportedEncodingException
 */
public Revision(String revision) throws UnsupportedEncodingException {
    if (revision == null) {
        throw new NullPointerException("Null revisons not allowed");
    }
    this.revision = MessageLibrary.toBytes(revision);
}

From source file:net.jforum.services.SmilieService.java

/**
 * Adds a new smilie//  ww w. j av a2  s .c o m
 *
 * @param smilie
 */
public void add(Smilie smilie, UploadedFile uploadedFile) {
    this.applyCommonConstraints(smilie);

    if (smilie.getId() > 0) {
        throw new ValidationException("Cannot add an existing (id > 0) smilie");
    }

    String imageDiskName = this.saveImage(uploadedFile);

    if (imageDiskName == null) {
        throw new NullPointerException("Could not find the smile file to save");
    }

    smilie.setDiskName(imageDiskName);

    this.repository.add(smilie);
}