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:com.supermy.base.service.WebMetaService.java

@Autowired
public WebMetaService(EntityManagerFactory factory) {
    if (factory.unwrap(SessionFactory.class) == null) {
        throw new NullPointerException("factory is not a hibernate factory");
    }/*www.  j  a v a2 s  .  co m*/
    this.sessionfactory = factory.unwrap(SessionFactory.class);
}

From source file:Main.java

/**
 * Creates a string with {@code toString()} of each object with the given separator.
 *
 * <pre>//w  w w  .  ja v a  2s . co  m
 * expect:
 * join(",", ["a"]) == "a"
 * join(",", ["a", "b", "c"]) == "a,b,c"
 * join(",", []) == ""
 * </pre>
 *
 * The {@code separator} must not be null and {@code objects} must not be null.
 *
 * @param separator The string by which to join each string representation
 * @param objects The objects to join the string representations of
 * @return The joined string
 */
public static String join(String separator, Iterable<?> objects) {
    if (separator == null) {
        throw new NullPointerException("The 'separator' cannot be null");
    }
    if (objects == null) {
        throw new NullPointerException("The 'objects' cannot be null");
    }

    StringBuilder string = new StringBuilder();
    Iterator<?> iterator = objects.iterator();
    if (iterator.hasNext()) {
        string.append(iterator.next().toString());
        while (iterator.hasNext()) {
            string.append(separator);
            string.append(iterator.next().toString());
        }
    }
    return string.toString();
}

From source file:com.amazonaws.services.dynamodbv2.xspec.Path.java

private List<PathElement> parse(String path) {
    if (path == null) {
        throw new NullPointerException("path");
    }/*w w w .j  a  v  a 2s  .com*/

    final String[] split = path.split(Pattern.quote("."));
    final List<PathElement> elements = new ArrayList<PathElement>();

    for (String element : split) {
        int index = element.indexOf('[');
        if (index == -1) {
            elements.add(new NamedElement(element));
            continue;
        }

        if (index == 0) {
            throw new IllegalArgumentException("Bogus path: " + path);
        }

        elements.add(new NamedElement(element.substring(0, index)));

        do {
            element = element.substring(index + 1);
            index = element.indexOf(']');

            if (index == -1) {
                throw new IllegalArgumentException("Bogus path: " + path);
            }

            int arrayIndex = Integer.parseInt(element.substring(0, index));
            elements.add(new ArrayIndexElement(arrayIndex));

            element = element.substring(index + 1);
            index = element.indexOf('[');

            if (index > 0)
                throw new IllegalArgumentException("Bogus path: " + path);
        } while (index != -1);

        if (!element.isEmpty()) {
            throw new IllegalArgumentException("Bogus path: " + path);
        }
    }

    return elements;
}

From source file:com.ibm.soatf.component.soap.builder.ResourceUtils.java

private static Path parsePath(String resourcePath) {
    if (resourcePath == null) {
        throw new NullPointerException("resourcePath cannot be null");
    }/*from  w w  w.j a v a2 s .  co m*/
    Path path = new Path();
    path.packagePath = getFullPath(resourcePath);
    path.resourcePath = FilenameUtils.getName(resourcePath);
    return path;
}

From source file:br.com.caelum.vraptor.ioc.spring.WebinfClassesPatternResolver.java

public WebinfClassesPatternResolver(String webinfClassesDirectory) {
    if (webinfClassesDirectory == null) {
        throw new NullPointerException("web inf class directory cant be null");
    }/*from w  w w.  j  a v  a2 s  .  com*/
    this.webinfClassesDirectory = webinfClassesDirectory;

}

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

public Revision(byte[] revision) {
    if (revision == null) {
        throw new NullPointerException("Null revisons not allowed");
    }//ww  w .  j  ava2  s.c o  m
    this.revision = revision;
}

From source file:edu.harvard.iq.dataverse.mydata.SolrQueryFormatter.java

/**
 *
 * @param sliceOfIds//  ww  w.ja  v a  2s  .c  om
 * @param paramName
 * @return
 */
private String formatIdsForSolrClause(List<Long> sliceOfIds, String paramName, String dvObjectType) { //='entityId'):
    if (paramName == null) {
        throw new NullPointerException("paramName cannot be null");
    }
    if (sliceOfIds == null) {
        throw new NullPointerException("sliceOfIds cannot be null");
    }
    if (sliceOfIds.isEmpty()) {
        throw new IllegalStateException("sliceOfIds must have at least 1 value");
    }

    List<String> idList = new ArrayList<>();
    for (Long id : sliceOfIds) {
        if (id != null) {
            idList.add("" + id);
        }
    }
    String orClause = StringUtils.join(idList, " ");
    String qPart = "(" + paramName + ":(" + orClause + "))";
    if (dvObjectType != null) {
        qPart = "(" + paramName + ":(" + orClause + ") AND " + SearchFields.TYPE + ":(" + dvObjectType + "))";
        //valStr;
    }

    return qPart;
}

From source file:com.github.rvesse.airline.builder.AbstractBuilder.java

/**
 * Checks a value given for a parameter is not null
 * /* w w  w.j a  v a 2 s . com*/
 * @param value
 *            Value
 * @param paramName
 *            Parameter
 */
protected final void checkNotNull(String value, String paramName) {
    if (value == null)
        throw new NullPointerException(String.format("%s cannot be null", paramName));
}

From source file:edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties.java

public static ConfigurationProperties getBean(HttpSession session) {
    if (session == null) {
        throw new NullPointerException("session may not be null.");
    }/*from ww w  .j ava  2s  .  c o m*/
    return getBean(session.getServletContext());
}

From source file:net.dv8tion.jda.utils.InviteUtil.java

/**
 * Takes an invite url or invite code and changes it into an {@link net.dv8tion.jda.utils.InviteUtil.Invite Invite}.
 * If the url or code isn't a proper invite, this returns <code>null</code>
 *
 * @param code// w  w w . java2 s.  c  o  m
 *          The invite url or code
 * @return
 *      An {@link net.dv8tion.jda.utils.InviteUtil.Invite Invite} representing the invite specified by the provided
 *      code or url. This will return <code>null</code> if the provided code or url is invalid.
 * @throws java.lang.NullPointerException
 *      If the provided String is null.
 */
public static Invite resolve(String code) {
    if (code == null)
        throw new NullPointerException("The provided invite code/url was null.");
    if (code.startsWith("http")) {
        String[] split = code.split("/");
        code = split[split.length - 1];
    }
    JSONObject object = new JDAImpl(false, false, false).getRequester()
            .get(Requester.DISCORD_API_PREFIX + "invite/" + code).getObject();
    if (object != null && object.has("code") && object.has("guild")) {
        JSONObject guild = object.getJSONObject("guild");
        JSONObject channel = object.getJSONObject("channel");
        return new Invite(object.getString("code"), guild.getString("name"), guild.getString("id"),
                channel.getString("name"), channel.getString("id"), channel.getString("type").equals("text"));
    }
    return null;
}