List of usage examples for java.lang NullPointerException NullPointerException
public NullPointerException(String s)
From source file:Main.java
/** * Creates a list of strings from a string within tokens. Empty tokens will * be omitted: If a string within tokens is <code>"a,,b,,c"</code> and the * delimiter string is <code>","</code>, the returned list of strings * contains the tree elements <code>"a", "b", "c"</code>. * * @param string String within tokens * @param delimiter Delimiter that separates the tokens. Every character * of the delimiter string is a separate delimiter. If * the string within tokens is <code>"I,like:ice"</code> * and the delimiter string is <code>",:"</code>, the * returned list of strings contains the three elements * <code>"I", "like", "ice"</code>. * @return List of strings/* w w w. j a v a2 s.c o m*/ */ public static List<String> stringTokenToList(String string, String delimiter) { if (string == null) { throw new NullPointerException("string == null"); } if (delimiter == null) { throw new NullPointerException("delimiter == null"); } StringTokenizer tokenizer = new StringTokenizer(string, delimiter); List<String> list = new ArrayList<>(tokenizer.countTokens()); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken()); } return list; }
From source file:Main.java
public static void valiObjectIsNull(Object object, String objectName) throws NullPointerException { if (object == null) { throw new NullPointerException("Object '" + objectName + "' is null!"); }/*ww w.ja v a2s.c o m*/ }
From source file:Main.java
public static boolean isSymLink(File filePath) throws IOException { if (filePath == null) throw new NullPointerException("filePath cannot be null"); File canonical;/*from www. ja va 2 s. c o m*/ if (filePath.getParent() == null) { canonical = filePath; } else { File canonDir = filePath.getParentFile().getCanonicalFile(); canonical = new File(canonDir, filePath.getName()); } return !canonical.getCanonicalFile().equals(canonical.getAbsoluteFile()); }
From source file:Main.java
/** * Checks if passed object is not null (and throws {@link NullPointerException} if not). * Thrown exception contains proper message with passed object name for easier identification. * //from ww w .java 2 s . co m * @param objectName name of passed object * @param objectToCheck object to be checked * * @throws NullPointerException if passed object is null */ public static <T> void notNull(String objectName, T objectToCheck) { if (objectToCheck == null) throw new NullPointerException(objectName + " is null"); }
From source file:ca.uhn.fhir.util.ObjectUtil.java
public static <T> T requireNonNull(T obj, String message) { if (obj == null) throw new NullPointerException(message); return obj;/*from w w w. j a v a 2s. c o m*/ }
From source file:Main.java
/** * Creates an Iterable instance that just returns the given Iterator from its iterator() method. * /* w w w.jav a 2 s .c om*/ * This is useful for using an iterator in a foreach loop directly. * * <p> * Example use: * <pre> * for (Object o : iterable(iterator)) { ... } * </pre> * * @throws NullPointerException if list is {@code null} */ public static <T> Iterable<T> iterable(final Iterator<T> iter) { if (iter == null) throw new NullPointerException("iter parameter is null"); //$NON-NLS-1$ return new Iterable<T>() { @Override public Iterator<T> iterator() { return iter; } }; }
From source file:com.nabla.wapp.server.general.Assert.java
/** * Test if object is not null//from w w w. ja v a 2 s . co m * @param ref - object to test * @throws NullPointerException if object is null */ public static <T> void notNull(final T ref) throws NullPointerException { if (log.isDebugEnabled()) { if (ref == null) throw new NullPointerException("assertNotNull failed"); } }
From source file:Main.java
/** * Given an ordered list of directories to look in, locate the specified file. * Returns <code>null</code> if file not found. * @param loadpaths the ordered list of paths to search. * @param filename the name of the file. * @return a File object corresponding to the file. <code>null</code> if * file not found.//from ww w . ja v a 2 s . com */ public static File locateFile(List<String> loadpaths, String filename) { if (filename == null) { throw new NullPointerException("No filename provided"); } if (loadpaths == null) { throw new NullPointerException("No loadpaths provided."); } for (String path : loadpaths) { File file = new File(path, filename); if (file.exists()) { return file; } } return null; }
From source file:Main.java
public static MarginLayoutParams newLayoutParam(ViewGroup placer, int width, int height) { if (placer instanceof FrameLayout) { return new FrameLayout.LayoutParams(width, height); } else if (placer instanceof RelativeLayout) { return new RelativeLayout.LayoutParams(width, height); } else if (placer == null) { throw new NullPointerException("placer is null"); } else {//from w w w. j ava 2s . c o m throw new IllegalArgumentException( "placer is neither FrameLayout nor RelativeLayout: " + placer.getClass().getName()); } }
From source file:Main.java
/** * Verify that the basic constraints of a {@link SafeStyles} are met. This * method is not a guarantee that the specified css is safe for use in a CSS * style attribute. It is a minimal set of assertions to check for common * errors.//w w w . j a v a2s . c o m * * @param styles the CSS properties string * @throws NullPointerException if the css is null * @throws AssertionError if the css does not meet the contraints */ static void verifySafeStylesConstraints(String styles) { if (styles == null) { throw new NullPointerException("css is null"); } // CSS properties must end in a semi-colon or they cannot be safely // composed with other properties. assert ((styles.trim().length() == 0) || styles.endsWith(";")) : "Invalid CSS Property: '" + styles + "'. CSS properties must be an empty string or end with a semi-colon (;)."; assert !styles.contains("<") && !styles.contains(">") : "Invalid CSS Property: '" + styles + "'. CSS should not contain brackets (< or >)."; }