-4

I calculate the sum of to variable getting from 2 request, the result is recovered but when I want to exploit it an NullPointerException is thrown:

 public List<Object[]> buildQuery4SConsistencyCheck(Societe societe,ParamSociete paramSociete,Date 
 periode) throws TechnicalNGEException {

    String sql="select SUM(INTERNAL_AMOUNT) from (select   vR.montant_valorise as INTERNAL_AMOUNT"
            + " from sigma02.valorisation_location vR inner join sigma02.eds  soc on 
                  vR.societe=soc.id_eds "
            + "inner join sigma02.chantier  ch on vR.compte_de_recette=ch.id_eds"
            + " inner join sigma02.edsm on  vR.id_edsm=edsm.id_edsm inner join sigma02.eds  "
            + "edsR on vR.compte_de_recette=edsR.id_eds where vR.montant_facture !=0 and 
                   vR.statut_traitment "
            + "like 'F' and vR.societe = 11 and vR.date_piece='2018-1-31' union all select "
            + " vDep.montant_valorise as INTERNAL_AMOUNT  FROM sigma02.valorisation_location"
            + " vDep inner join sigma02.eds soc on vDep.societe=soc.id_eds "
            + "inner join sigma02.eds as edsDep on vDep.chantier_materiel=edsDep.id_eds "
            + "inner join sigma02.chantier as chDep on vDep.chantier_materiel=chDep.id_eds"
            + " inner join sigma02.edsm on vDep.id_edsm=edsm.id_edsm  WHERE vDep.montant_facture<>0"
            + " and vDep.statut_traitment='F' and vDep.societe=11 and vDep.date_piece='2018-1-31'  ) 
     as somme";
     List<Object[]> result = null;
        try {
            SQLQuery query = session.createSQLQuery(sql);
            result =  query.list();

        } catch (HibernateException e) {
            bloqException(e);
        }

        return result;

}

in this line where the exception is thrown:

 @Autowired
private ValorisationLocationDAO valorisationLocationDAO;
 Object[]   c= 
 valorisationLocationDAO.buildQuery4SConsistencyCheck(societe,paramSociete,periode).get(0);

After debbuggin I get this in result:

[93648.40, null, null, null, null, null, null, null, null, null]

this is the error :

  Caused by: java.lang.NullPointerException
at com.nge.sigma.reprise.util.BatchLogger.log(BatchLogger.java:205) [sigma- 
 reprise-0.0.14-SNAPSHOT.jar:]
at com.nge.sigma.reprise.util.BatchLogger.logDebug(BatchLogger.java:193) 
[sigma-reprise-0.0.14-SNAPSHOT.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_221]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_221]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_221]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.8.0_221]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at com.sun.proxy.$Proxy447.logDebug(Unknown Source)
imaneBlh
  • 29
  • 1
  • 3
  • 10
  • 4
    Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – AndiCover Jan 22 '20 at 13:24
  • @AndiCover Unfortunately no – imaneBlh Jan 22 '20 at 13:39

2 Answers2

0

Where is the Exception? There is no NullPointerException. It looks you are getting confused between variables having null value and NullPointerException which is expected as you are returning SUM(INTERNAL_AMOUNT); a single value whose value is 93648.40. Other variables are null as expected.

Rahul Agrawal
  • 623
  • 1
  • 5
  • 18
0

It's was a cast problem, I change the return type of the methode to int

 public int buildQuery4SConsistencyCheck(Societe societe,Date periode) throws 
 TechnicalNGEException {
    String sql="select SUM(INTERNAL_AMOUNT) from (select   vR.montant_valorise as 
    INTERNAL_AMOUNT"
        + " from sigma02.valorisation_location vR inner join sigma02.eds  soc on 
              vR.societe=soc.id_eds "
        + "inner join sigma02.chantier  ch on vR.compte_de_recette=ch.id_eds"
        + " inner join sigma02.edsm on  vR.id_edsm=edsm.id_edsm inner join sigma02.eds  "
        + "edsR on vR.compte_de_recette=edsR.id_eds where vR.montant_facture !=0 and 
               vR.statut_traitment "
        + "like 'F' and vR.societe = 11 and vR.date_piece='2018-1-31' union all 
    select vDep.montant_valorise as INTERNAL_AMOUNT  FROM 
       sigma02.valorisation_location"
        + " vDep inner join sigma02.eds soc on vDep.societe=soc.id_eds "
        + "inner join sigma02.eds as edsDep on vDep.chantier_materiel=edsDep.id_eds "
        + "inner join sigma02.chantier as chDep on 
           vDep.chantier_materiel=chDep.id_eds"
        + " inner join sigma02.edsm on vDep.id_edsm=edsm.id_edsm  WHERE 
           vDep.montant_facture<>0"
        + " and vDep.statut_traitment='F' and vDep.societe=11 and 
               vDep.date_piece='2018-1-31'  ) 
        as somme";       
    int result =-1;
        try {
            SQLQuery query = session.createSQLQuery(sql);
                 // cast 
             result = ((BigDecimal) query.uniqueResult()).intValue();


        } catch (HibernateException e) {
            bloqException(e);
        }

        return result;


}
imaneBlh
  • 29
  • 1
  • 3
  • 10