This might be an odd question but we are required to suppress a certain type of exception from a certain method from printing on to our debug console.
This exception I am talking about is happening on LazyDataModel for Primefaces where the setter method is throwing Arithmetic Exception: / by zero when in a certain phase of the datatable lifecycle the pageSize is 0 and it goes on to throw that exception.
The parent class method from the Primefaces framework for LazyDataModel.class is:
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex % this.pageSize;
}
The common solution out there is below:
@Override
public void setRowIndex(int rowIndex) {
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
}
else {
super.setRowIndex(rowIndex % getPageSize());
}
}
However, the solution posted above still manages to throw Arthimetic Exception: / by zero when pageSize is 0. We've tried catching the exception and manipulating the values in our method so the Exception is not thrown but that breaks the UI.
When we don't have the override method there everything works fine but the exception is still printed. Our management does not want this.
The solution I am thinking of now is to remove my override method and try to suppress the exception from JVM or the method itself. And the management seems happy to accept that. On those lines is there any approach out there I can try?
Update 1: As requested by PSo, we are not explicitly setting pageSize anywhere (backend or frontend).
Datatable Definition in the view file
<p:dataTable widgetVar="myWidgetName" var="myDataVariable" value="#{myManagedBean.dataList}" rowIndexVar="myRowIndexVariable" id="myDataTableId"
styleClass="myStyleClass" emptyMessage="No Records Found"
rowStyleClass="myRowStyleClass"
scrollable="false"
paginator="true"
rows="5"
paginatorAlwaysVisible="true"
paginatorPosition="both"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {JumpToPageDropdown} {PageLinks} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="10"
selection="#{myManagedBean.mySelectedRecord}"
rendered="true">
<p:column headerText="#">
<h:outputText>#{myDataRowIndex}</h:outputText></p:column>
<p:column styleClass="myColumnStyleClass">
</p:column>
</p:dataTable>