Hieu Nguyen
Hieu Nguyen

Reputation: 11

Google Cloud Vision crashes without exception caught

I recently encountering an annoying bug that only happen in 1 out of our 3 environments (Amazon EC2 to be specific). When I send a request to the Cloud API to receive tags about the picture. The function crashes but I don't see any exception caught by the try catch. The function works fine until June 1st but I don't know why it doesn't anymore (other 2 environments work just fine).

Here are the code:

try {
             GoogleCredentials cred = GoogleCredentials.fromStream(new FileInputStream(coreConfig.googleCreds()));
             log.error("GoogleCredentials cred = GoogleCredentials.fromStream(new FileInputStream(coreConfig.googleCreds()));");
             ImageAnnotatorSettings imageAnnotatorSettings =  ImageAnnotatorSettings.newBuilder()
                              .setCredentialsProvider(FixedCredentialsProvider.create(cred))
                              .build();
            ImageAnnotatorClient vision = ImageAnnotatorClient.create(imageAnnotatorSettings);
            log.error("ImageAnnotatorClient vision = ImageAnnotatorClient.create(imageAnnotatorSettings);");
              byte[] data = IOUtils.toByteArray(is);
              ByteString bs = ByteString.copyFrom(data);
              // Builds the image annotation request
              List<AnnotateImageRequest> requests = new ArrayList<>();
              log.error("ByteString bs = ByteString.copyFrom(data);");
              Image img = Image.newBuilder().setContent(bs).build();
              log.error("  Image img = Image.newBuilder().setContent(bs).build();");
              Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
              log.error("Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();");
              AnnotateImageRequest request = AnnotateImageRequest.newBuilder()
                  .addFeatures(feat)
                  .setImage(img)
                  .build();
              requests.add(request);
              log.error("requests.add(request);");
              // Performs label detection on the image file
              BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
              log.error("BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);");
              List<AnnotateImageResponse> responses = response.getResponsesList();           
              log.error("List<AnnotateImageResponse> responses = response.getResponsesList();");
              for (AnnotateImageResponse res : responses) {
                if (res.hasError()) {
                    throw new ServiceException(ServiceStatus.BAD_REQUEST, res.getError().getMessage());             
                }        
                for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {              
                  tags.append("===" + annotation.getDescription().replaceAll("\\s+",""));
                  log.error("tags.append(\"===\" + annotation.getDescription().replaceAll(\"\\\\s+\",\"\"));");
                }
              } 
              return tags;
        }catch(Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());          
            return null;
//          throw new ServiceException(ServiceStatus.BAD_REQUEST, e.getMessage());
        }

Here are the details about it:

Here are the details about it

Upvotes: 0

Views: 428

Answers (1)

Hieu Nguyen
Hieu Nguyen

Reputation: 11

It seems like an old version of guava (in this case 17.0-jdk) caused this crash. You still have to remove the old version not only from the pom.xml but also in the lib folder of the .war file.

Upvotes: 1

Related Questions