-4

Checkmarx scan is giving below bug ""So and so class performs an operation that could be expected to throw an exception and is not properly wrapped with try-catch block.This constitutes improper exceptional handling"

Below is the code snippet

public List getDataforTable(String query,List\<String\> preparedStatementParameterList){

Query queryObj = devEntityManager.createNativeQuery (query, Tuple.class);

for (String dbParameter:preparedStatementParameterList){    
if(dbParameter != null && dbParameter.contains("-")) {    
  String\[\] filterParameter= dbParameter.split("\\\\\\\~\\\\|"); 
  if(filterParameter.length = 2)    
    queryObj.setParameter(filterParameter \[0\], filterParameter\[1\]);    
  else queryObj.setParameter (filterParameter\[0\]), "");    
}

}

@SuppressWarnings("unchecked") List\<Tuple\> queryRows = queryObj.getResultList();

final List\<Map\<String, Object\>\> formattedRows = new ArrayList\<\>();    
utility.resultExtraction (queryRows, formattedRows);    
return formattedRows;    
}

Checkmarx scan highlighted below line of code and expecting exception handling for the same

queryRows = queryObj.getResultList();

I tried with try-catch block but its not working

Stultuske
  • 9,296
  • 1
  • 25
  • 37
  • Checkmarx should tell you which exact line is the problem. If it's still not clear to you, show us what you tried (where you put the try/catch) and why it didn't work. – Jorn Aug 25 '23 at 12:35
  • checkmarx highlighting this line and saying "So and so class performs an operation that could be expected to throw an exception and is not properly wrapped with try-catch block.This constitutes improper exceptional handling" @SuppressWarnings("unchecked") List queryRows = queryObj.getResultList(); – srinivas reddy Aug 25 '23 at 12:40

0 Answers0