-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPORT-848: added try catch statements to catch NullPointerException #170
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,15 @@ | |
package org.openmrs.module.reporting.web.reports.renderers; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.hibernate.PropertyValueException; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import org.springframework.stereotype.Controller; | ||
|
@@ -96,7 +99,7 @@ else if (successUrl.startsWith(pathToRemove)) { | |
* @throws InstantiationException | ||
*/ | ||
@RequestMapping("/module/reporting/reports/renderers/saveDelimitedTextReportDesign") | ||
public String saveDelimitedTextReportDesign(ModelMap model, HttpServletRequest request, | ||
public String saveDelimitedTextReportDesign(ModelMap model, HttpServletRequest request, HttpSession sesion, | ||
@RequestParam(required=false, value="uuid") String uuid, | ||
@RequestParam(required=true, value="name") String name, | ||
@RequestParam(required=false, value="description") String description, | ||
|
@@ -110,7 +113,7 @@ public String saveDelimitedTextReportDesign(ModelMap model, HttpServletRequest r | |
ReportService rs = Context.getService(ReportService.class); | ||
ReportDesign design = null; | ||
Properties delimiters = new Properties(); | ||
|
||
try { | ||
if (StringUtils.isNotEmpty(uuid)) { | ||
design = rs.getReportDesignByUuid(uuid); | ||
} | ||
|
@@ -148,5 +151,10 @@ else if (successUrl.startsWith(pathToRemove)) { | |
} | ||
design = rs.saveReportDesign(design); | ||
return "redirect:" + successUrl; | ||
}catch(PropertyValueException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mozzy11 , what happens when a |
||
sesion.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"reporting.nullPropertyValues.error"); | ||
return "module/reporting/reports/renderers/delimitedTextReportRenderer"; | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,11 @@ | |
import java.util.Set; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.hibernate.PropertyValueException; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import org.openmrs.module.reporting.report.renderer.XlsReportRenderer; | ||
|
@@ -111,7 +113,7 @@ else if (successUrl.startsWith(pathToRemove)) { | |
*/ | ||
@SuppressWarnings("unchecked") | ||
@RequestMapping("/module/reporting/reports/renderers/saveExcelReportRenderer") | ||
public String saveExcelReportRenderer(ModelMap model, HttpServletRequest request, | ||
public String saveExcelReportRenderer(ModelMap model, HttpServletRequest request, HttpSession sesion, | ||
@RequestParam(required=false, value="uuid") String uuid, | ||
@RequestParam(required=true, value="name") String name, | ||
@RequestParam(required=false, value="description") String description, | ||
|
@@ -126,7 +128,7 @@ public String saveExcelReportRenderer(ModelMap model, HttpServletRequest request | |
) throws ClassNotFoundException, InstantiationException, IllegalAccessException { | ||
ReportService rs = Context.getService(ReportService.class); | ||
ReportDesign design = null; | ||
|
||
try { | ||
if (StringUtils.isNotEmpty(uuid)) { | ||
design = rs.getReportDesignByUuid(uuid); | ||
} | ||
|
@@ -213,5 +215,9 @@ else if (successUrl.startsWith(pathToRemove)) { | |
} | ||
design = rs.saveReportDesign(design); | ||
return "redirect:" + successUrl; | ||
}catch(PropertyValueException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same applies here and anywhere else in this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did several testing of that , and instead of a Null Pointer Exception being throen when an empty parameter is passed to the controller, its a PropertyValueEception that is thrown . i think the NPE is already manged by the util methods used there in that specific controller where i was catching the propertValueException |
||
sesion.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"reporting.nullPropertyValues.error"); | ||
return "module/reporting/reports/renderers/excelReportRenderer"; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was only here , where an empty parameter passed to the controller throws a NPE