soehler / androidsvg

Automatically exported from code.google.com/p/androidsvg
0 stars 0 forks source link

Code smell. SVGImageView.java uses Exception to handle multiplicity of "svg" attribute #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Declare the SVGImageView in a layout file (xml)
2. Specify an asset file using the "svg" attribute.

What is the expected output? What do you see instead?

The svg is rendered correctly and the app runs fine. However logcat is filled 
with Warnings for behavior that should be handled more gracefully and doesn't 
need warnings to be raised.

What version of the product are you using? On what operating system?

1.2 I think. I cloned the repo today.
Android 2.3.3 (API 10)

Please provide any additional information below.

One example is SVGImageView.internalSetImageURI(Uri uri) on line 138: is = 
getContext().getContentResolver().openInputStream(uri);

If one chooses to specify an asset file in the "svg" attribute than the uri is 
a string containing the relative path of the svg file in the assets/ folder. 
Clearly this will cause the above line to fail and throw an exception.

This behavior is expected however, based on how the "svg" attribute accepts 
multiple possible inputs (as defined in 
https://code.google.com/p/androidsvg/wiki/SVGImageView). Unfortunately the code 
captures the exception using a generic Exception (frowned upon behavior) and 
then writes a warning log (for expected behavior).

Solution:

Use specific Exceptions to catch the various possibilities and handle them 
accordingly. For instance I prefixed the general Exception catch with this 
single line:

catch (FileNotFoundException e) { return false; }

No more warnings for expected behavior.

Original issue reported on code.google.com by a...@spoton.com on 31 Oct 2013 at 8:11

GoogleCodeExporter commented 9 years ago
Fixed in local revision 272.

Improved error handling and reporting throughout SVGImageView.

This fix will be in the next release (1.3).

Thanks abid.

Original comment by paul.leb...@gmail.com on 31 Oct 2013 at 8:56

GoogleCodeExporter commented 9 years ago
This fix is available in the 1.2.1 release.

Original comment by paul.leb...@gmail.com on 31 Jan 2014 at 1:32