List of usage examples for java.lang NullPointerException getStackTrace
public StackTraceElement[] getStackTrace()
From source file:org.sakaiproject.genericdao.hibernate.GenericDaoTest.java
/** * Test method for {@link org.sakaiproject.genericdao.hibernate.HibernateGenericDao#setPersistentClasses(java.util.List)}. *///from w w w . j av a 2s .com @Test public void testSetPersistentClasses() { HibernateGenericDao genericDao = new HibernateGenericDao(); List<String> l = new ArrayList<String>(); l.add("org.sakaiproject.genericdao.test.GenericTestObject"); genericDao.setPersistentClasses(l); // test null list l = null; try { genericDao.setPersistentClasses(l); Assert.fail("Should have thrown a NullPointerException"); } catch (NullPointerException e) { Assert.assertNotNull(e.getStackTrace()); } // test empty list l = new ArrayList<String>(); try { genericDao.setPersistentClasses(l); Assert.fail("Should have thrown an IllegalArgumentException"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e.getStackTrace()); } }
From source file:net.sf.jasperreports.engine.util.JdkGlyphFixTextMeasurer.java
protected boolean isJdkGlyphError(NullPointerException e) { StackTraceElement[] stackTrace = e.getStackTrace(); if (stackTrace.length == 0) { if (log.isDebugEnabled()) { log.debug("Caught exception with no stacktrace; " + (catchEmptyStacktrace ? "" : "not ") + "treating as JDK Glyph exception"); }//from w ww . ja v a 2 s. co m return catchEmptyStacktrace; } StackTraceElement top = stackTrace[0]; return top.getClassName().startsWith(JDK_EXCEPTION_CLASS_PREFIX); }
From source file:gov.wa.wsdot.android.wsdot.ui.CameraImageFragment.java
public void onLoadFinished(Loader<Drawable> loader, Drawable data) { swipeRefreshLayout.setRefreshing(false); mImage.setImageDrawable(data);/* ww w . ja v a 2 s. c om*/ try { shareAction.setShareIntent(createShareIntent()); } catch (NullPointerException e) { Log.e(TAG, "createShareIntent() returned NULL: " + e.getStackTrace()); } }
From source file:gov.wa.wsdot.android.wsdot.ui.camera.CameraImageFragment.java
public void onLoadFinished(Loader<Drawable> loader, Drawable data) { mSwipeRefreshLayout.setRefreshing(false); mImage.setImageDrawable(data);/*from w w w .j a va 2 s. c o m*/ try { //shareAction.setShareIntent(createShareIntent()); } catch (NullPointerException e) { Log.e(TAG, "createShareIntent() returned NULL: " + e.getStackTrace()); } }
From source file:com.daro.persistence.generic.dao.GenericDaoImpl.java
/** * Get Current Session from Session Factory. * // ww w . ja v a 2s . c o m * @return Session Session instance * @throws PersistenceException */ protected Session getCurrentSession() throws PersistenceException { Session session = null; try { session = this.sessionFactory.getCurrentSession(); } catch (java.lang.NullPointerException nullPpointEx) { logger.error("Persistence layer error: " + nullPpointEx.getStackTrace()); throw new PersistenceException(PersistenceError.SESSION_FACTORY_NULL, nullPpointEx.getCause()); } catch (Exception ex) { logger.error("Persistence layer error: " + ex.getStackTrace()); PersistenceError error = PersistenceError.PERSISTENCE_INTERNAL_ERROR; throw new PersistenceException(error, ex.getCause()); } return session; }
From source file:org.sakaiproject.crudplus.logic.test.CrudPlusLogicImplTest.java
/** * Test method for {@link org.sakaiproject.crudplus.logic.impl.CrudPlusLogicImpl#saveItem(org.sakaiproject.crudplus.model.CrudPlusItem)}. *//*from ww w. j a v a 2 s . co m*/ public void testSaveItem() { // set up the mock objects userDirectoryService.getCurrentUser(); // expect this to be called userDirectoryServiceControl.setReturnValue(new TestUser(USER_ID)); // return this toolManager.getCurrentPlacement(); // expect this to be called toolManagerControl.setReturnValue(new TestPlacement(SITE_ID)); // return this CrudPlusItem item = new CrudPlusItem("New item title", USER_ID, SITE_ID, ITEM_HIDDEN, new Date()); logicImpl.saveItem(item); Long itemId = item.getId(); Assert.assertNotNull(itemId); // test saving an incomplete item CrudPlusItem incompleteItem = new CrudPlusItem(); incompleteItem.setTitle("New incomplete item"); incompleteItem.setHidden(ITEM_HIDDEN); // activate the mock objects userDirectoryServiceControl.replay(); toolManagerControl.replay(); // mock object is needed here logicImpl.saveItem(incompleteItem); Long incItemId = item.getId(); Assert.assertNotNull(incItemId); item = logicImpl.getItemById(incItemId); Assert.assertNotNull(item); Assert.assertEquals(item.getOwnerId(), USER_ID); Assert.assertEquals(item.getSiteId(), SITE_ID); // test saving a null value for failure try { logicImpl.saveItem(null); Assert.fail("Should have thrown NullPointerException"); } catch (NullPointerException e) { Assert.assertNotNull(e.getStackTrace()); log.info("Could not save null item (this is correct)"); } // verify the mock object was used userDirectoryServiceControl.verify(); toolManagerControl.verify(); }
From source file:com.sldeditor.test.unit.tool.vector.VectorToolTest.java
@Test public void testVectorToolDBDataSource() { TestMissingSLDAttributes testAttribute = new TestMissingSLDAttributes(); List<CheckAttributeInterface> checkList = new ArrayList<CheckAttributeInterface>(); checkList.add(testAttribute);// w ww .j a v a2 s .c om CheckAttributeFactory.setOverideCheckList(checkList); String testsldfile = "/polygon/sld/polygon_polygonwithdefaultlabel.sld"; TestSLDEditor testSLDEditor = null; try { testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null); } catch (Exception e) { e.printStackTrace(); } RenderPanelImpl.setUnderTest(true); InputStream inputStream = VectorToolTest.class.getResourceAsStream(testsldfile); if (inputStream == null) { Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream); } else { File f = null; try { f = stream2file(inputStream); try { testSLDEditor.openFile(f.toURI().toURL()); } catch (NullPointerException nullException) { nullException.printStackTrace(); StackTraceElement[] stackTraceElements = nullException.getStackTrace(); System.out.println(stackTraceElements[0].getMethodName()); } f.delete(); } catch (IOException e1) { e1.printStackTrace(); } } // Fields extracted from the SLD file DataSourceInterface dataSource = DataSourceFactory.createDataSource(null); Collection<PropertyDescriptor> propertyList = dataSource.getPropertyDescriptorList(); assertEquals(2, propertyList.size()); Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } AttributeDescriptor name = (AttributeDescriptor) map.get("name"); assertNotNull(name); GeometryDescriptor geometry = (GeometryDescriptor) map.get("geom"); assertNotNull(geometry); File tempFolder = Files.createTempDir(); TestVectorTool vectorTool = new TestVectorTool(testSLDEditor); try { InputStream gpkgInputStream = VectorToolTest.class .getResourceAsStream("/test/sld_cookbook_polygon.gpkg"); final File gpkgFile = new File(tempFolder, "sld_cookbook_polygon.gpkg"); try (FileOutputStream out = new FileOutputStream(gpkgFile)) { IOUtils.copy(gpkgInputStream, out); } DatabaseConnection databaseConnection = DatabaseConnectionFactory .getConnection(gpkgFile.getAbsolutePath()); DatabaseFeatureClassNode dbFCTreeNode = new DatabaseFeatureClassNode(null, databaseConnection, "sld_cookbook_polygon"); DatabaseConnectionManager.getInstance().addNewConnection(null, databaseConnection); vectorTool.testSetDataSource(dbFCTreeNode); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(3, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNotNull(name); geometry = (GeometryDescriptor) map.get("geometry"); assertNotNull(geometry); AttributeDescriptor pop = (AttributeDescriptor) map.get("pop"); assertNotNull(pop); // Create SLD from geopackage layer vectorTool.testImportFeatureClass(dbFCTreeNode); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(3, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNotNull(name); geometry = (GeometryDescriptor) map.get("geometry"); assertNotNull(geometry); pop = (AttributeDescriptor) map.get("pop"); assertNotNull(pop); // Release locks dataSource.reset(); } catch (IOException e) { e.printStackTrace(); fail(); } // Tidy up so the remaining unit tests are ok JFrame frame = testSLDEditor.getApplicationFrame(); frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); testSLDEditor = null; clearDown(); // Delete the shape files we extracted purgeDirectory(tempFolder); }
From source file:com.sldeditor.test.unit.tool.vector.VectorToolTest.java
/** * Test method for {@link com.sldeditor.tool.vector.VectorTool#VectorTool(com.sldeditor.common.SLDEditorInterface)}. *//*from w w w .j a va 2 s .c o m*/ @Test public void testVectorToolFileDataSource() { TestMissingSLDAttributes testAttribute = new TestMissingSLDAttributes(); List<CheckAttributeInterface> checkList = new ArrayList<CheckAttributeInterface>(); checkList.add(testAttribute); CheckAttributeFactory.setOverideCheckList(checkList); String testsldfile = "/polygon/sld/polygon_polygonwithdefaultlabel.sld"; TestSLDEditor testSLDEditor = null; try { testSLDEditor = TestSLDEditor.createAndShowGUI2(null, null, true, null); } catch (Exception e) { e.printStackTrace(); } InputStream inputStream = VectorToolTest.class.getResourceAsStream(testsldfile); if (inputStream == null) { Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream); } else { File f = null; try { f = stream2file(inputStream); try { testSLDEditor.openFile(f.toURI().toURL()); } catch (NullPointerException nullException) { nullException.printStackTrace(); StackTraceElement[] stackTraceElements = nullException.getStackTrace(); System.out.println(stackTraceElements[0].getMethodName()); } f.delete(); } catch (IOException e1) { e1.printStackTrace(); } } // Fields extracted from the SLD file DataSourceInterface dataSource = DataSourceFactory.createDataSource(null); Collection<PropertyDescriptor> propertyList = dataSource.getPropertyDescriptorList(); assertEquals(2, propertyList.size()); Map<String, PropertyDescriptor> map = new HashMap<String, PropertyDescriptor>(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } AttributeDescriptor name = (AttributeDescriptor) map.get("name"); assertNotNull(name); GeometryDescriptor geometry = (GeometryDescriptor) map.get("geom"); assertNotNull(geometry); File tempFolder = Files.createTempDir(); TestVectorTool vectorTool = new TestVectorTool(testSLDEditor); try { // Set a shape file as a data source - that matches the SLD File matchingShpFile = extractShapeFile(tempFolder, "/test/sld_cookbook_polygon.zip"); FileTreeNode fileTreeNode = new FileTreeNode(matchingShpFile.getParentFile(), matchingShpFile.getName()); vectorTool.testSetDataSource(fileTreeNode); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(3, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNotNull(name); geometry = (GeometryDescriptor) map.get("the_geom"); assertNotNull(geometry); AttributeDescriptor pop = (AttributeDescriptor) map.get("pop"); assertNotNull(pop); // Set a shape file as a data source - that does not match the SLD File nonMatchingShpFile = extractShapeFile(tempFolder, "/test/states.zip"); FileTreeNode fileTreeNode2 = new FileTreeNode(nonMatchingShpFile.getParentFile(), nonMatchingShpFile.getName()); vectorTool.testSetDataSource(fileTreeNode2); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(23, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNull(name); geometry = (GeometryDescriptor) map.get("the_geom"); assertNotNull(geometry); pop = (AttributeDescriptor) map.get("pop"); assertNull(pop); assertEquals(1, testAttribute.getMissingFieldList().size()); assertEquals("name", testAttribute.getMissingFieldList().get(0)); // Create SLD from shape file vectorTool.testImportFile(fileTreeNode); dataSource = DataSourceFactory.createDataSource(null); propertyList = dataSource.getPropertyDescriptorList(); assertEquals(3, propertyList.size()); map.clear(); for (PropertyDescriptor property : propertyList) { map.put(property.getName().getLocalPart(), property); } name = (AttributeDescriptor) map.get("name"); assertNotNull(name); geometry = (GeometryDescriptor) map.get("the_geom"); assertNotNull(geometry); pop = (AttributeDescriptor) map.get("pop"); assertNotNull(pop); // Release locks dataSource.reset(); } catch (IOException e) { e.printStackTrace(); fail(); } // Tidy up so the remaining unit tests are ok JFrame frame = testSLDEditor.getApplicationFrame(); frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); testSLDEditor = null; clearDown(); // Delete the shape files we extracted purgeDirectory(tempFolder); }
From source file:org.catechis.Stats.java
private void addErrorToLog(java.lang.NullPointerException npe) { log.add("toString : " + npe.toString()); log.add("getMessage : " + npe.getMessage()); log.add("getLocalziedMessage:" + npe.getLocalizedMessage()); Throwable throwup = npe.getCause(); Throwable init_cause = npe.initCause(throwup); log.add("thowable.msg :" + init_cause.toString()); StackTraceElement[] ste = npe.getStackTrace(); for (int j = 0; j < ste.length; j++) { log.add(j + " - " + ste[j].toString()); if (j > 6) { log.add(" ..."); break; }//from www . ja va 2s . c o m } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.DatatypeRetryController.java
public void doPost(HttpServletRequest req, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(req, response, SimplePermission.EDIT_ONTOLOGY.ACTION)) { return;/* w w w .jav a2 s . co m*/ } VitroRequest request = new VitroRequest(req); //create an EditProcessObject for this and put it in the session EditProcessObject epo = super.createEpo(request); DatatypeDao dDao = request.getUnfilteredWebappDaoFactory().getDatatypeDao(); epo.setDataAccessObject(dDao); Datatype objectForEditing = null; String action = ""; if (request.getParameter("id") != null) { int id = Integer.parseInt(request.getParameter("id")); if (id > 0) { try { log.debug("Trying to retrieve datatype " + id); objectForEditing = dDao.getDatatypeById(id); action = "update"; } catch (NullPointerException e) { log.error("Need to implement 'record not found' error message."); } } } else { action = "insert"; objectForEditing = new Datatype(); } epo.setOriginalBean(objectForEditing); //put this in the parent class? //make a simple mask for the class's id Object[] simpleMaskPair = new Object[2]; simpleMaskPair[0] = "Id"; simpleMaskPair[1] = Integer.valueOf(objectForEditing.getId()); epo.getSimpleMask().add(simpleMaskPair); //set the getMethod so we can retrieve a new bean after we've inserted it try { Class[] args = new Class[1]; args[0] = int.class; epo.setGetMethod(dDao.getClass().getDeclaredMethod("getDatatypeById", args)); } catch (NoSuchMethodException e) { log.error("EntityRetryController could not find the entityById method in the facade"); } epo.setPostInsertPageForwarder(new DatatypeInsertPageForwarder()); epo.setPostDeletePageForwarder(new DatatypeDeletePageForwarder()); FormObject foo = new FormObject(); epo.setFormObject(foo); FormUtils.populateFormFromBean(objectForEditing, action, foo); //for now, this is also making the value hash - need to separate this out RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp"); request.setAttribute("scripts", "/templates/edit/formBasic.js"); request.setAttribute("formJsp", "/templates/edit/specific/datatype_retry.jsp"); request.setAttribute("title", "Datatype Editing Form"); request.setAttribute("_action", action); request.setAttribute("unqualifiedClassName", "Datatype"); setRequestAttributes(request, epo); try { rd.forward(request, response); } catch (Exception e) { log.error("VclassRetryContro" + "ller could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }