Skip to Content
0
Former Member
Oct 13, 2014 at 01:19 PM

ProductService not throwing UnknownIdentifierException

413 Views

Hi all

I'm using the method getProductForCode(String) in the ProductService. Because I am not sure whether the input String is a valid SKU or not, I surrounded that method call with a try-catch block in order to anticipate for possible UnknownIdentifierException exceptions.

However, it seems that exception is never thrown even though the provided SKU surely doesn't exist. I assign a variable to the method call and it stays null, which causes a NullPointerException on the next line.

Anybody knows why the product service doesn't throw its exceptions as stated in the documentation?

Thanks in advance

Sander

The code I tested this issue with:

 try
 {
     final ProductModel product = productService.getProductForCode(nonExistingSku);
     final String url = product.getGalleryImages()...; // product == null -> NPE
 
     dto.setSkuKnown(true);
     dto.setMediaUrl(url);
 }
 catch (final UnknownIdentifierException | AmbiguousIdentifierException e)
 {
     dto.setSkuKnown(false);
     System.out.println("Unknown SKU");
 }