The project is developed with Java 1.8 and has two branches, in the developer branch everything works correctly and in the new feature we migrated from log4j 1 to version 2, as well as updating some other libraries. After this update, the following method doesn’t work as expected:
public boolean esFechaNominaCorrectaLanzaExcepcion(GastoPersonal gasto,Date fecDesde,Date fecHasta)throws FechaNominaIncorrectaException,FechaNominaMayorActualException{
boolean devolver=true;
Calendar c=Calendar.getInstance();
try {
//primero se comprueba que mes/año no sean superiores a los de la fecha actual
if(gasto.getAnioPeriodo().intValue()>c.get(Calendar.YEAR))
throw new FechaNominaMayorActualException();
else if( (gasto.getAnioPeriodo().intValue()==c.get(Calendar.YEAR)) && (gasto.getMesPeriodo()>(c.get(Calendar.MONTH)+1)) )
throw new FechaNominaMayorActualException();
//y ahora se comprueba que el mes/año de la nomina esta entre los de fecDesde y fecHasta
if( gasto.getAnioPeriodo().intValue()> (fecHasta.getYear()+1900) )
throw new FechaNominaIncorrectaException();
else if( (gasto.getAnioPeriodo().intValue()==(fecHasta.getYear()+1900)) && (gasto.getMesPeriodo()>(fecHasta.getMonth()+1)) )
throw new FechaNominaIncorrectaException();
if( gasto.getAnioPeriodo().intValue()< (fecDesde.getYear()+1900) )
throw new FechaNominaIncorrectaException();
else if( (gasto.getAnioPeriodo().intValue()==(fecDesde.getYear()+1900)) && (gasto.getMesPeriodo()<(fecDesde.getMonth()+1)) )
throw new FechaNominaIncorrectaException();
} catch (FechaNominaMayorActualException e) {
log.error("Fecha mes/año de la nomina mayor a la fecha actual.", e);
devolver = false;
} catch (FechaNominaIncorrectaException e) {
log.error("Fecha mes/año de la nomina incorrecta de acuerdo a las fechas del proyecto.", e);
devolver = false;
} catch (Exception e) {
log.catching(e);
devolver = false;
}
return devolver;
}
//--------------------------------------------------------------------------------------------------
public boolean esFechaNominaCorrectaLanzaExcepcion(GastoPersonal gasto, String fecDesde, String fecHasta) throws FechaNominaIncorrectaException, FechaNominaMayorActualException {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
try {
Date dateDesde = sdf.parse(fecDesde);
Date dateHasta = sdf.parse(fecHasta);
return esFechaNominaCorrectaLanzaExcepcion(gasto, dateDesde, dateHasta);
} catch (ParseException e) {
log.error("Error al parsear las fechas desde/fecha hasta: " + fecDesde + " / " + fecHasta, e);
throw new FechaNominaIncorrectaException("Formato de fecha inválido: " + e.getMessage(), e);
}
}```
This method should validate the dates and if an exception is thrown, display the message in the user interface, catch the exception and follow the flow of the application.
However, the application crashes whenever the exception is thrown.
Any suggestions on how to get the expected result?