You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2017/12/01 15:34:30 UTC

[myfaces-tobago] 01/04: TOBAGO-1782: Clean up * using "try with resources" (new with Java 7) ** avoid NPE

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit bcdb1c176206c7d3f60fa339441aacd8edb22bd7
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Fri Dec 1 11:56:57 2017 +0100

    TOBAGO-1782: Clean up
    * using "try with resources" (new with Java 7)
    ** avoid NPE
---
 .../org/apache/myfaces/tobago/example/demo/SourceFileReader.java    | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SourceFileReader.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SourceFileReader.java
index 94e05c3..5666652 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SourceFileReader.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SourceFileReader.java
@@ -38,10 +38,12 @@ public abstract class SourceFileReader {
     final String viewId = facesContext.getViewRoot().getViewId();
     final String file = viewId.substring(0, viewId.lastIndexOf("/")) + "/" + filename;
     try (final InputStream resourceAsStream = externalContext.getResourceAsStream(file)) {
-      return IOUtils.toString(resourceAsStream, "UTF-8");
+      if (resourceAsStream != null) {
+        return IOUtils.toString(resourceAsStream, "UTF-8");
+      }
     } catch (final IOException e) {
       LOG.error("", e);
-      return null;
     }
+    return null;
   }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.