Skip to content

Commit

Permalink
GRIFFON-535 do not eat up exceptions when creating artifact instances
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 16, 2012
1 parent 681bd12 commit 187ed7d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,11 @@ public static void registerExceptionHandler() {
Thread.setDefaultUncaughtExceptionHandler(new GriffonExceptionHandler());
System.setProperty("sun.awt.exception.handler", GriffonExceptionHandler.class.getName());
}

public static void handleThrowable(Throwable t) {
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(
Thread.currentThread(),
t
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import static griffon.util.ConfigUtils.getConfigValue;
import static griffon.util.ConfigUtils.getConfigValueAsString;
import static griffon.util.GriffonExceptionHandler.handleThrowable;
import static griffon.util.GriffonExceptionHandler.sanitize;
import static griffon.util.GriffonNameUtils.isBlank;
import static java.util.Arrays.asList;
Expand Down Expand Up @@ -142,10 +143,12 @@ private static void readAndSetConfiguration(GriffonApplication app) {

app.setBuilderConfig(loadConfig(configSlurper, app.getBuilderClass(), GriffonApplication.Configuration.BUILDER.getName()));

Object events = safeNewInstance(app.getEventsClass());
if (events != null) {
app.setEventsConfig(events);
app.addApplicationEventListener(app.getEventsConfig());
if (app.getEventsClass() != null) {
Object events = safeNewInstance(app.getEventsClass());
if (events != null) {
app.setEventsConfig(events);
app.addApplicationEventListener(app.getEventsConfig());
}
}

Object log4jConfig = app.getConfig().get("log4j");
Expand Down Expand Up @@ -391,13 +394,22 @@ public static Object newInstance(GriffonApplication app, Class klass, String typ
LOG.debug("Instantiating " + klass.getName() + " with type '" + type + "'");
}

Object instance = safeNewInstance(klass);

GriffonClass griffonClass = app.getArtifactManager().findGriffonClass(klass);
MetaClass mc = griffonClass != null ? griffonClass.getMetaClass() : expandoMetaClassFor(klass);
enhance(app, klass, mc, instance);
Object instance = null;
try {
instance = klass.newInstance();
} catch (InstantiationException e) {
throw new GriffonException(e);
} catch (IllegalAccessException e) {
throw new GriffonException(e);
}

app.event(GriffonApplication.Event.NEW_INSTANCE.getName(), asList(klass, type, instance));
// GRIFFON-535
if (instance != null) {
GriffonClass griffonClass = app.getArtifactManager().findGriffonClass(klass);
MetaClass mc = griffonClass != null ? griffonClass.getMetaClass() : expandoMetaClassFor(klass);
enhance(app, klass, mc, instance);
app.event(GriffonApplication.Event.NEW_INSTANCE.getName(), asList(klass, type, instance));
}
return instance;
}

Expand Down Expand Up @@ -461,6 +473,7 @@ private static Object safeNewInstance(String className) {
try {
return loadClass(className).newInstance();
} catch (Exception e) {
handleThrowable(e);
return null;
}
}
Expand All @@ -469,6 +482,7 @@ private static Object safeNewInstance(Class clazz) {
try {
return clazz.newInstance();
} catch (Exception e) {
handleThrowable(e);
return null;
}
}
Expand Down

0 comments on commit 187ed7d

Please sign in to comment.