Make logging less verbose and better check disposed status of widgets
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 20 Dec 2023 07:46:39 +0000 (08:46 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 20 Dec 2023 07:46:39 +0000 (08:46 +0100)
osgi/equinox/org.argeo.cms.lib.equinox/src/org/argeo/cms/equinox/http/jetty/EquinoxJettyServer.java
swt/org.argeo.cms.swt/src/org/argeo/cms/swt/CmsSwtUtils.java
swt/org.argeo.cms.swt/src/org/argeo/cms/swt/acr/SwtTabbedArea.java
swt/rap/org.argeo.cms.swt.rap/src/org/argeo/cms/web/CmsWebEntryPoint.java

index cd4d5cee80949b754c4b6b71b14eda82bd8df78a..935be167a8577af83c721d0fadeb392ac3c37444 100644 (file)
@@ -14,6 +14,7 @@ import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionIdListener;
 import javax.servlet.http.HttpSessionListener;
 
+import org.argeo.api.cms.CmsLog;
 import org.argeo.cms.jetty.CmsJettyServer;
 import org.eclipse.equinox.http.servlet.HttpServiceServlet;
 import org.eclipse.jetty.ee8.nested.SessionHandler;
@@ -23,6 +24,7 @@ import org.osgi.framework.Constants;
 
 /** A {@link CmsJettyServer} integrating with Equinox HTTP framework. */
 public class EquinoxJettyServer extends CmsJettyServer {
+       private final static CmsLog log = CmsLog.getLog(EquinoxJettyServer.class);
        private static final String INTERNAL_CONTEXT_CLASSLOADER = "org.eclipse.equinox.http.jetty.internal.ContextClassLoader";
 
        @Override
@@ -95,6 +97,10 @@ public class EquinoxJettyServer extends CmsJettyServer {
                        thread.setContextClassLoader(contextLoader);
                        try {
                                httpServiceServlet.service(req, res);
+                       } catch (IllegalStateException e) {
+                               // context is probably in shutdown
+                               if (log.isTraceEnabled())
+                                       log.error("Cannot process request", e);
                        } finally {
                                thread.setContextClassLoader(current);
                        }
index 3a91dbc23dc5db5db2c7569f75d00a272b3f8d42..d97bc4c35ad2bb89b81663e7d17d15899fd8ded0 100644 (file)
@@ -61,6 +61,8 @@ public class CmsSwtUtils {
        }
 
        public static CmsView getCmsView(Control parent) {
+               if (parent.isDisposed())
+                       return null;
                // find parent shell
                Shell topShell = parent.getShell();
                while (topShell.getParent() != null)
@@ -219,7 +221,7 @@ public class CmsSwtUtils {
 
        /** Style widget */
        public static <T extends Widget> T style(T widget, String style) {
-               if (style == null)
+               if (style == null || widget.isDisposed())
                        return widget;// does nothing
                EclipseUiSpecificUtils.setStyleData(widget, style);
                if (widget instanceof Control) {
index b65bc3b6a3a28171ff0719e69dd9c2739d1e4e0c..83cb4698402166eee52a3ffa6b1f1c79d2bb89d7 100644 (file)
@@ -231,7 +231,7 @@ public class SwtTabbedArea extends Composite {
 
        public Content getCurrentContext() {
                SwtSection section = getCurrentSection();
-               if (section != null) {
+               if (section != null && !section.isDisposed()) {
                        return section.getContent();
                } else {
                        return null;
index d0f4d41f83d5adf06ed14d80be51271ffc4efc77..02e5da3666edd040753a53d34a1331165cac96ad 100644 (file)
@@ -287,7 +287,8 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                                } catch (SWTError e) {
                                        SWTError swtError = (SWTError) e;
                                        if (swtError.code == SWT.ERROR_FUNCTION_DISPOSED) {
-                                               log.error("Unexpected SWT error in event loop, ignoring it. " + e.getMessage());
+                                               if (log.isTraceEnabled())
+                                                       log.error("Unexpected SWT error in event loop, ignoring it. " + e.getMessage());
                                                continue eventLoop;
                                        } else {
                                                log.error("Unexpected SWT error in event loop, shutting down...", e);