From 1ab95f22bb30d2d218f683ca4fa6d72e2b96576a Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 20 Apr 2013 12:24:42 -0500 Subject: [PATCH] IDEMPIERE-859 NPE on Attachment where is not storage provider configured / Show cause of problems when toolbar buttons cannot action --- .../org/compiere/model/MStorageProvider.java | 9 +++-- .../webui/adwindow/ADWindowToolbar.java | 38 +++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MStorageProvider.java b/org.adempiere.base/src/org/compiere/model/MStorageProvider.java index 506c84757a..c3fa25aad5 100644 --- a/org.adempiere.base/src/org/compiere/model/MStorageProvider.java +++ b/org.adempiere.base/src/org/compiere/model/MStorageProvider.java @@ -21,6 +21,7 @@ import java.util.Properties; import org.adempiere.base.Service; import org.adempiere.base.ServiceQuery; +import org.adempiere.exceptions.AdempiereException; public class MStorageProvider extends X_AD_StorageProvider { /** @@ -43,8 +44,8 @@ public class MStorageProvider extends X_AD_StorageProvider { method = "DB"; query.put("method", method); IAttachmentStore store = Service.locator().locate(IAttachmentStore.class, query).getService(); - if (store == null){ - log.saveError("Error", "No attachment storage provider found"); + if (store == null) { + throw new AdempiereException("No attachment storage provider found"); } return store; } @@ -56,8 +57,8 @@ public class MStorageProvider extends X_AD_StorageProvider { method = "DB"; query.put("method", method); IArchiveStore store = Service.locator().locate(IArchiveStore.class, query).getService(); - if (store == null){ - log.saveError("Error", "No archive storage provider found"); + if (store == null) { + throw new AdempiereException("No archive storage provider found"); } return store; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java index 8770cedd46..f1fc6f1be0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java @@ -17,7 +17,6 @@ package org.adempiere.webui.adwindow; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; @@ -36,6 +35,7 @@ import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.event.ToolbarListener; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.theme.ThemeManager; +import org.adempiere.webui.window.FDialog; import org.compiere.model.MRole; import org.compiere.model.MToolBarButton; import org.compiere.model.MToolBarButtonRestrict; @@ -43,6 +43,7 @@ import org.compiere.model.X_AD_ToolBarButton; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Msg; +import org.compiere.util.ValueNamePair; import org.zkoss.image.AImage; import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.ui.Component; @@ -355,25 +356,24 @@ public class ADWindowToolbar extends FToolbar implements EventListener Method method = tListener.getClass().getMethod(methodName, (Class[]) null); method.invoke(tListener, (Object[]) null); } - catch(SecurityException e) + catch (Exception e) { - log.log(Level.SEVERE, "Could not invoke Toolbar listener method: " + methodName + "()", e); - } - catch(NoSuchMethodException e) - { - log.log(Level.SEVERE, "Could not invoke Toolbar listener method: " + methodName + "()", e); - } - catch(IllegalArgumentException e) - { - log.log(Level.SEVERE, "Could not invoke Toolbar listener method: " + methodName + "()", e); - } - catch(IllegalAccessException e) - { - log.log(Level.SEVERE, "Could not invoke Toolbar listener method: " + methodName + "()", e); - } - catch(InvocationTargetException e) - { - log.log(Level.SEVERE, "Could not invoke Toolbar listener method: " + methodName + "()", e); + String msg = null; + ValueNamePair vp = CLogger.retrieveError(); + if (vp != null) { + msg = vp.getName(); + } + if (msg == null) { + Throwable cause = e.getCause(); + if (cause != null) { + msg = cause.getLocalizedMessage(); + } + } + if (msg == null) { + msg = "Could not invoke Toolbar listener method: " + methodName + "()"; + } + FDialog.error(windowNo, this, "Error", msg); + log.log(Level.SEVERE, msg, e); } } this.event = null;