Skip to content

Commit

Permalink
Fixed Configuration deserialization.
Browse files Browse the repository at this point in the history
XML config may contain additional objects that are used in Configuration constructor. So they should be skipped during deserialization.
  • Loading branch information
Victor Osolovskiy committed Aug 6, 2015
1 parent 625f7c0 commit e0fe540
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/main/java/ftldb/Configurator.java
Expand Up @@ -68,12 +68,24 @@ public static synchronized void setConfiguration(Configuration config) {
public static Configuration newConfiguration(InputStream configXMLInputStream) {
XMLDecoder decoder = new XMLDecoder(configXMLInputStream, null, new ExceptionListener() {
public void exceptionThrown(Exception e) {
throw (e instanceof RuntimeException) ? (RuntimeException) e : new RuntimeException(e);
throw ((e instanceof RuntimeException) && !(e instanceof ArrayIndexOutOfBoundsException))
? (RuntimeException) e
: new RuntimeException(e);
}
});
Configuration config = (Configuration) decoder.readObject();
Object obj;
do {
try {
obj = decoder.readObject();
} catch (ArrayIndexOutOfBoundsException e) {
obj = null;
}
if (obj == null) {
throw new RuntimeException("Provided XML contains no " + Configuration.class.getName() + " objects");
}
} while (!(obj instanceof Configuration));
decoder.close();
return config;
return (Configuration) obj;
}


Expand Down Expand Up @@ -121,7 +133,7 @@ public static synchronized void dropConfiguration() {

private static void ensureConfigurationIsSet() {
if (config == null) {
throw new RuntimeException("FTLDB configuration is not initialized");
throw new NullPointerException("FTLDB configuration is not initialized");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/plsql/ftldb_api.pkb
Expand Up @@ -123,7 +123,7 @@ is

c_config constant varchar2(32767) :=
'<?xml version="1.0" encoding="UTF-8"?>
<java version="1.0" class="java.beans.XMLDecoder">
<java version="1.4.0" class="java.beans.XMLDecoder">
<object class="ftldb.DefaultConfiguration">
<void property="templateLoader">
<object class="ftldb.oracle.DatabaseTemplateLoader">
Expand Down
2 changes: 1 addition & 1 deletion src/test/ftl/ftldb_config.xml
Expand Up @@ -16,7 +16,7 @@
limitations under the License.
-->
<java version="1.0" class="java.beans.XMLDecoder">
<java version="1.4.0" class="java.beans.XMLDecoder">
<object class="ftldb.DefaultConfiguration">
<void property="templateLoader">
<object class="freemarker.cache.FileTemplateLoader"/>
Expand Down

0 comments on commit e0fe540

Please sign in to comment.