How to control an unexpected nullPointer Exception [duplicate]

0

I have a problem that only happens when I upload changes in quality environments and whose server is the WAS websphere application server in my local I am using tomcat 7 with eclipse, the detail is that local does not mark error (Eclipse) but already in quality (where the application is hosted) in the WAS generates an error of nullpointerException this is the code where the error is generated.

private double calculaInversion(String nb_serie,List<VivVAACInversion> catalogoInversion) {

          String rs=VAACServiceImpl.correspondencia.get(nb_serie);
            double id=0;

        try {

            for (VivVAACInversion vivVAACInversion : catalogoInversion) {
                if(rs.equalsIgnoreCase(vivVAACInversion.getNombreClave())){
                    id=vivVAACInversion.getIdInversion();
                }
            }



        }catch(Exception e) {
            System.out.println( "exception: " + e.getMessage());
        }

        return id;
    }

I tried to enter a try catch but this is not enough to control the Exception, could you help me in how I could control it with a validator with a if that this method is executed normally and that nullpointerexception disappear?

I remain attentive and if it is necessary that I do not understand with pleasure I put it, kind regards.

    
asked by JUAN JOSE BUSTAMANTE SOLIS 16.05.2018 в 18:40
source

1 answer

0

The problem of wanting to skip an Exception if you do not know why it is, is that the problem may be that your local server is not detecting the problem, which in theory comes from the information you process is different. I would put several if's that I show you in order to understand where is the null field that is generating the exception:

private double calculaInversion(String nb_serie,List<VivVAACInversion> catalogoInversion) {
  try{
      if (nb == null) {
          throw new IllegalArgumentException(" serie nula");
      }
      if (catalogoInversion == null) {
          throw new IllegalArgumentException("catalogo nulo");
      }
      String rs=VAACServiceImpl.correspondencia.get(nb_serie);
      if (rs == null) {
          throw new IllegalStateException("serie reportada nula o no localizada");
      }
      double id=0;

      for (VivVAACInversion vivVAACInversion : catalogoInversion) {
           String nombre = (vivVAACInversion.getNombreClave());
           if (nombre == null) {
               throw new IllegalStateExeception("hay una clave nula en el catalogo");
           }
            if(rs.equalsIgnoreCase(nombre){
                id=vivVAACInversion.getIdInversion();
                //aquí también preguntaría a menos que el método retorne un int.
            }
        }

    }catch(Exception e) {
        System.out.println( "exception: " + e.getMessage());
    }

    return id;
}

Already with this I could see where the null that is generated is and then see how to solve the problem.

    
answered by 16.05.2018 в 21:36