List of usage examples for java.lang NullPointerException NullPointerException
public NullPointerException()
From source file:simple.crawler.http.HttpClientUtil.java
public static String fetch(HttpClient httpclient, String uri) throws Exception { if (httpclient == null) { throw new NullPointerException(); }//from w ww . j a v a2s . c o m if (uri == null) { throw new NullPointerException(); } HttpGet get = new HttpGet(uri); return getContentBodyAsString(httpclient.execute(get)); }
From source file:com.pokercompany.stringcalc.StringCalculator.java
public int add(String numbers) throws Exception { if (numbers == null) { throw new NullPointerException(); }//w ww . j av a 2 s .c om if (numbers.equals("")) { return 0; } if (!numbers.matches("-?[0-9]+([" + separator + "]-?[0-9]+)*[" + separator + "]?")) { throw new NumberFormatException("Bad character(s) in input string: " + numbers); } List<String> numbersList = Arrays.asList(numbers.split("(?<!\\" + separator + ")[" + separator + "]")); List<String> negativeNumbers = StringCalcUtil.getListWherePatternMatches(numbersList, "[-][0-9]+"); if (negativeNumbers.size() > 0) { throw new Exception("Negative not allowed: " + StringUtils.join(negativeNumbers.iterator(), ",")); } int sum = 0; for (String stringNumber : numbersList) { sum += Integer.valueOf(stringNumber); } return sum; }
From source file:ClassUtils.java
/** * Get the ClassLoader to use. We always use the current Thread's * Context ClassLoader. Assumption is that all threads within the * application share the same ClassLoader. *//* ww w . ja va 2 s. c o m*/ private static ClassLoader getClassLoader() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { throw new NullPointerException(); } return cl; }
From source file:com.hd.stringcalculator.StringCalculator.java
public int add(String numbers) throws NegativeNumberException { if (numbers == null) { throw new NullPointerException(); } else if (numbers.isEmpty()) { return 0; }/*w w w. j av a 2 s . c om*/ if (!numbers.matches( "-?[0-9]+((" + Pattern.quote(separator) + ")-?[0-9]+)*(" + Pattern.quote(separator) + ")?")) { throw new IllegalArgumentException("Bad character(s) in input string: " + numbers); } List<String> numbersList = Arrays .asList(numbers.split("(?<!" + Pattern.quote(separator) + ")" + Pattern.quote(separator))); List<String> negativeNumbers = new StringListFilter("[-][0-9]+").filter(numbersList); if (negativeNumbers.size() > 0) { throw new NegativeNumberException(StringUtils.join(negativeNumbers.iterator(), ", ")); } int sum = 0; for (String stringNumber : numbersList) { sum += Integer.valueOf(stringNumber); } return sum; }
From source file:net.chunkyhosting.Roe.CHGManagerLauncher.utils.JSON.java
public static JSONObject readJsonFromFile(File file) throws FileNotFoundException, IOException, NullPointerException { String json = "NULL"; BufferedReader reader = new BufferedReader(new FileReader(file.toString())); String read = ""; while ((read = reader.readLine()) != null) { json = json + read;/*w w w . j a va 2 s . co m*/ } reader.close(); if (!json.equalsIgnoreCase("NULL")) { return stringToJson(json); } throw new NullPointerException(); }
From source file:com.lxht.emos.data.cache.intf.HessianUtil.java
/** * ?.// w ww . ja va 2s. c om * * @param obj ?? * @param fileName ????. * @throws IOException */ public static void serialize(Object obj, String fileName) throws IOException { if (obj == null) throw new NullPointerException(); File file = new File(fileName); // ?. if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } FileOutputStream fos = new FileOutputStream(file); HessianOutput ho = new HessianOutput(fos); ho.writeObject(obj); ho.flush(); ho.close(); fos.close(); }
From source file:Main.java
/** * Submits a value-returning task for execution on the EDT and * returns a Future representing the pending results of the task. * * @param task the task to submit// w w w. ja v a2 s .c o m * @return a Future representing pending completion of the task * @throws NullPointerException if the task is null */ public static <V> Future<V> submit(Callable<V> task) { if (task == null) { throw new NullPointerException(); } FutureTask<V> future = new FutureTask<V>(task); execute(future); return future; }
From source file:XMLResourceBundleControl.java
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { if ((baseName == null) || (locale == null) || (format == null) || (loader == null)) { throw new NullPointerException(); }//from w ww. j a v a 2s . c o m ResourceBundle bundle = null; if (!format.equals(XML)) { return null; } String bundleName = toBundleName(baseName, locale); String resourceName = toResourceName(bundleName, format); URL url = loader.getResource(resourceName); if (url == null) { return null; } URLConnection connection = url.openConnection(); if (connection == null) { return null; } if (reload) { connection.setUseCaches(false); } InputStream stream = connection.getInputStream(); if (stream == null) { return null; } BufferedInputStream bis = new BufferedInputStream(stream); bundle = new XMLResourceBundle(bis); bis.close(); return bundle; }
From source file:de.hasait.genesis.base.util.GenesisUtils.java
public static void assertNotNull(final Object pValue) { if (pValue == null) { throw new NullPointerException(); }// w ww . j av a2 s.c om }
From source file:com.milaboratory.primitivio.JSONSerializer.java
public JSONSerializer(Class<?> type) { if (type == null) throw new NullPointerException(); this.type = type; }