From 0e3b55601457da2d5bc9edb85d2de701409aeb5c Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 1 Oct 2012 14:08:33 +0300 Subject: [PATCH] Avoid throwing exceptions from toString, log message instead (#9804) Change-Id: Ia2f8504a0fe75ab3a7c4746d533e5fd012e2a69c --- .../com/vaadin/data/util/AbstractProperty.java | 18 +++++++++++++++--- .../com/vaadin/data/util/IndexedContainer.java | 18 ++++++++++++++++-- .../data/util/sqlcontainer/ColumnProperty.java | 18 ++++++++++++++++-- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/server/src/com/vaadin/data/util/AbstractProperty.java b/server/src/com/vaadin/data/util/AbstractProperty.java index 76d47039d0..aefe00ad32 100644 --- a/server/src/com/vaadin/data/util/AbstractProperty.java +++ b/server/src/com/vaadin/data/util/AbstractProperty.java @@ -18,6 +18,7 @@ package com.vaadin.data.util; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; +import java.util.logging.Logger; import com.vaadin.data.Property; @@ -78,9 +79,17 @@ public abstract class AbstractProperty implements Property, @Deprecated @Override public String toString() { - throw new UnsupportedOperationException( - "Use Property.getValue() instead of " + getClass() - + ".toString()"); + getLogger() + .warning( + "You are using Property.toString() instead of getValue() to get the value for a " + + getClass().getSimpleName() + + ". This will not be supported starting from Vaadin 7.1 " + + "(your debugger might call toString() and cause this message to appear)."); + T v = getValue(); + if (v == null) { + return null; + } + return v.toString(); } /* Events */ @@ -277,4 +286,7 @@ public abstract class AbstractProperty implements Property, return Collections.EMPTY_LIST; } + private static Logger getLogger() { + return Logger.getLogger(AbstractProperty.class.getName()); + } } diff --git a/server/src/com/vaadin/data/util/IndexedContainer.java b/server/src/com/vaadin/data/util/IndexedContainer.java index e957d958a9..7273b28b66 100644 --- a/server/src/com/vaadin/data/util/IndexedContainer.java +++ b/server/src/com/vaadin/data/util/IndexedContainer.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.logging.Logger; import com.vaadin.data.Container; import com.vaadin.data.Item; @@ -961,8 +962,21 @@ public class IndexedContainer extends @Deprecated @Override public String toString() { - throw new UnsupportedOperationException( - "Use Property.getValue() instead of IndexedContainerProperty.toString()"); + getLogger() + .warning( + "You are using IndexedContainerProperty.toString() instead of getValue() to get the value for a " + + getClass().getSimpleName() + + ". This will not be supported starting from Vaadin 7.1 " + + "(your debugger might call toString() and cause this message to appear)."); + Object v = getValue(); + if (v == null) { + return null; + } + return v.toString(); + } + + private Logger getLogger() { + return Logger.getLogger(IndexedContainerProperty.class.getName()); } /** diff --git a/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java index 6e5ba0dc57..bd6b1a75bf 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java @@ -18,6 +18,7 @@ package com.vaadin.data.util.sqlcontainer; import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; +import java.util.logging.Logger; import com.vaadin.data.Property; import com.vaadin.data.util.converter.Converter.ConversionException; @@ -261,8 +262,21 @@ final public class ColumnProperty implements Property { @Deprecated @Override public String toString() { - throw new UnsupportedOperationException( - "Use ColumnProperty.getValue() instead of ColumnProperty.toString()"); + getLogger() + .warning( + "You are using ColumnProperty.toString() instead of getValue() to get the value for a " + + getClass().getSimpleName() + + ". This will not be supported starting from Vaadin 7.1 " + + "(your debugger might call toString() and cause this message to appear)."); + Object v = getValue(); + if (v == null) { + return null; + } + return v.toString(); + } + + private static Logger getLogger() { + return Logger.getLogger(ColumnProperty.class.getName()); } public void setOwner(RowItem owner) { -- 2.39.5