You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2019/12/09 10:16:55 UTC
[myfaces] branch master updated: better handling for empty
faces-config.xml
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new ef2e4e7 better handling for empty faces-config.xml
ef2e4e7 is described below
commit ef2e4e703188e18aede978a9fed4bdcddd609890
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Dec 9 11:16:47 2019 +0100
better handling for empty faces-config.xml
---
.../config/DefaultFacesConfigurationProvider.java | 42 +++++++++++++++++-----
1 file changed, 34 insertions(+), 8 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java b/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java
index d36929f..ab08bc3 100644
--- a/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java
+++ b/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.myfaces.config;
+import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import org.apache.myfaces.config.annotation.AnnotationConfigurator;
import org.apache.myfaces.config.element.FacesConfig;
@@ -376,7 +377,29 @@ public class DefaultFacesConfigurationProvider extends FacesConfigurationProvide
{
try
{
- FacesConfig webAppConfig = null;
+ // just return a empty FacesConfigImpl if the file is empty
+ // we just do a shortcut here, otherwise validateXML would log a error/exception
+ try (InputStream stream = ectx.getResourceAsStream(DEFAULT_FACES_CONFIG))
+ {
+ if (stream != null)
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = stream.read(buffer)) != -1)
+ {
+ out.write(buffer, 0, length);
+ }
+ out.flush();
+
+ String content = new String(out.toByteArray());
+ if (content.trim().isEmpty())
+ {
+ return new FacesConfigImpl();
+ }
+ }
+ }
+
// web application config
if (MyfacesConfig.getCurrentInstance(ectx).isValidateXML())
{
@@ -386,17 +409,20 @@ public class DefaultFacesConfigurationProvider extends FacesConfigurationProvide
validateFacesConfig(ectx, url);
}
}
- InputStream stream = ectx.getResourceAsStream(DEFAULT_FACES_CONFIG);
- if (stream != null)
+
+ try (InputStream stream = ectx.getResourceAsStream(DEFAULT_FACES_CONFIG))
{
- if (log.isLoggable(Level.INFO))
+ if (stream != null)
{
- log.info("Reading config /WEB-INF/faces-config.xml");
+ if (log.isLoggable(Level.INFO))
+ {
+ log.info("Reading config /WEB-INF/faces-config.xml");
+ }
+ return getUnmarshaller(ectx).getFacesConfig(stream, DEFAULT_FACES_CONFIG);
}
- webAppConfig = getUnmarshaller(ectx).getFacesConfig(stream, DEFAULT_FACES_CONFIG);
- stream.close();
}
- return webAppConfig;
+
+ return null;
}
catch (IOException e)
{