From a53c48ac6d9122baa90f1bbd1e86f40d34fd4093 Mon Sep 17 00:00:00 2001
From: Jesse Long
Date: Wed, 9 May 2012 17:57:52 +0200
Subject: [PATCH 1/3] Log exceptions to SLF4J
---
.../InstrumentationObjectSizeOfStrategy.java | 91 ++++++++++---------
1 file changed, 47 insertions(+), 44 deletions(-)
diff --git a/wicket-objectssizeof-agent/src/main/java/org/apache/wicket/util/instrument/InstrumentationObjectSizeOfStrategy.java b/wicket-objectssizeof-agent/src/main/java/org/apache/wicket/util/instrument/InstrumentationObjectSizeOfStrategy.java
index 65f418e0859..21621d2de7a 100644
--- a/wicket-objectssizeof-agent/src/main/java/org/apache/wicket/util/instrument/InstrumentationObjectSizeOfStrategy.java
+++ b/wicket-objectssizeof-agent/src/main/java/org/apache/wicket/util/instrument/InstrumentationObjectSizeOfStrategy.java
@@ -23,6 +23,8 @@
import java.lang.instrument.Instrumentation;
import org.apache.wicket.core.util.lang.WicketObjects.IObjectSizeOfStrategy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Object size of strategy that is based on instrumentation.
@@ -31,7 +33,52 @@
*/
public class InstrumentationObjectSizeOfStrategy implements IObjectSizeOfStrategy
{
+ private static final Logger log = LoggerFactory.getLogger(InstrumentationObjectSizeOfStrategy.class);
+ /**
+ * Instrumentation instance.
+ */
+ private final Instrumentation instrumentation;
+
+ /**
+ * Construct.
+ *
+ * @param instrumentation
+ */
+ public InstrumentationObjectSizeOfStrategy(Instrumentation instrumentation)
+ {
+ this.instrumentation = instrumentation;
+ }
+
+ /**
+ * Calculates full size of object iterating over its hierarchy graph.
+ *
+ * @param obj
+ * object to calculate size of
+ * @return object size
+ *
+ * @see org.apache.wicket.core.util.lang.WicketObjects.IObjectSizeOfStrategy#sizeOf(java.io.Serializable)
+ */
+ @Override
+ public long sizeOf(Serializable obj)
+ {
+ if (obj == null)
+ {
+ return 0;
+ }
+ try
+ {
+ SizeRecodingOuputStream recorder = new SizeRecodingOuputStream();
+ recorder.writeObject(obj);
+ return recorder.getTotalSize();
+ }
+ catch (IOException e)
+ {
+ log.error("Error calculating size of object", e);
+ return -1;
+ }
+ }
+
/**
* Records the size of an object and it's dependents as if they were serialized but using the
* instrumentation API to calculate.
@@ -81,48 +128,4 @@ protected Object replaceObject(Object obj) throws IOException
return obj;
}
}
-
- /**
- * Instrumentation instance.
- */
- private final Instrumentation instrumentation;
-
- /**
- * Construct.
- *
- * @param instrumentation
- */
- public InstrumentationObjectSizeOfStrategy(Instrumentation instrumentation)
- {
- this.instrumentation = instrumentation;
- }
-
- /**
- * Calculates full size of object iterating over its hierarchy graph.
- *
- * @param obj
- * object to calculate size of
- * @return object size
- *
- * @see org.apache.wicket.core.util.lang.WicketObjects.IObjectSizeOfStrategy#sizeOf(java.io.Serializable)
- */
- public long sizeOf(Serializable obj)
- {
- if (obj == null)
- {
- return 0;
- }
- try
- {
- SizeRecodingOuputStream recorder = new SizeRecodingOuputStream();
- recorder.writeObject(obj);
- return recorder.getTotalSize();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- return -1;
- }
-
- }
}
From 04185aebcd486ac04c7498cd0517a7248b46ab35 Mon Sep 17 00:00:00 2001
From: Jesse Long
Date: Wed, 9 May 2012 18:02:29 +0200
Subject: [PATCH 2/3] Log exceptions to SLF4J, not stdout
---
.../extensions/captcha/kittens/KittenCaptchaPanel.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
index f0e5756cf95..23dc7bfbb42 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/captcha/kittens/KittenCaptchaPanel.java
@@ -50,6 +50,8 @@
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.DynamicImageResource;
import org.apache.wicket.util.time.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A unique and fun-to-use captcha technique I developed at Thoof.
@@ -60,6 +62,8 @@ public class KittenCaptchaPanel extends Panel
{
private static final long serialVersionUID = 2711167040323855070L;
+ private static final Logger log = LoggerFactory.getLogger(KittenCaptchaPanel.class);
+
// The background grass area
private static BufferedImage grass = load("images/grass.png");
@@ -98,7 +102,7 @@ private static BufferedImage load(final String filename)
}
catch (IOException e)
{
- e.printStackTrace();
+ log.error("Error loading image", e);
return null;
}
}
@@ -379,7 +383,7 @@ private BufferedImage load(final String filename)
}
catch (IOException e)
{
- e.printStackTrace();
+ log.error("Error loading image", e);
return null;
}
}
From 888698fb895c8df73a92a3beb0b3383b2e6deb71 Mon Sep 17 00:00:00 2001
From: Jesse Long
Date: Wed, 9 May 2012 18:24:04 +0200
Subject: [PATCH 3/3] Remove DateConverter#get/setComponent() and
DateConverter#getLocale()
DateConverter#getLocale() was protected and never used - pointless.
DateConverter#get/setComponent() was used only by DateConverter#getLocale()
This helps prevent DateLabel and DateTextField from leaking this from the contructor.
---
.../apache/wicket/datetime/DateConverter.java | 38 +------------------
.../datetime/markup/html/basic/DateLabel.java | 1 -
.../markup/html/form/DateTextField.java | 2 +-
3 files changed, 3 insertions(+), 38 deletions(-)
diff --git a/wicket-datetime/src/main/java/org/apache/wicket/datetime/DateConverter.java b/wicket-datetime/src/main/java/org/apache/wicket/datetime/DateConverter.java
index 7962d3ca279..9aacbaf2191 100644
--- a/wicket-datetime/src/main/java/org/apache/wicket/datetime/DateConverter.java
+++ b/wicket-datetime/src/main/java/org/apache/wicket/datetime/DateConverter.java
@@ -20,7 +20,6 @@
import java.util.Locale;
import java.util.TimeZone;
-import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.request.WebClientInfo;
import org.apache.wicket.core.request.ClientInfo;
@@ -50,11 +49,6 @@ public abstract class DateConverter implements IConverter
*/
private final boolean applyTimeZoneDifference;
- /**
- * Optional component to use for determining the locale.
- */
- private Component component = null;
-
/**
* Construct.
When applyTimeZoneDifference is true, the current time is applied on the
* parsed date, and the date will be corrected for the time zone difference between the server
@@ -75,6 +69,7 @@ public DateConverter(boolean applyTimeZoneDifference)
* @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String,
* java.util.Locale)
*/
+ @Override
public Date convertToObject(String value, Locale locale)
{
if (Strings.isEmpty(value))
@@ -131,6 +126,7 @@ public Date convertToObject(String value, Locale locale)
* @see org.apache.wicket.util.convert.IConverter#convertToString(java.lang.Object,
* java.util.Locale)
*/
+ @Override
public String convertToString(Date value, Locale locale)
{
DateTime dt = new DateTime(value.getTime(), getTimeZone());
@@ -165,31 +161,12 @@ public final boolean getApplyTimeZoneDifference()
return applyTimeZoneDifference;
}
- /**
- * @return optional component to use for determining the locale.
- */
- public final Component getComponent()
- {
- return component;
- }
-
/**
* @param locale
* @return Gets the pattern that is used for printing and parsing
*/
public abstract String getDatePattern(Locale locale);
- /**
- * Sets component for getting the locale
- *
- * @param component
- * optional component to use for determining the locale.
- */
- public final void setComponent(Component component)
- {
- this.component = component;
- }
-
/**
* Gets the client's time zone.
*
@@ -212,17 +189,6 @@ protected TimeZone getClientTimeZone()
*/
protected abstract DateTimeFormatter getFormat(Locale locale);
- /**
- * Gets the locale to use.
- *
- * @return the locale from either the component if that is set, or from the session
- */
- protected Locale getLocale()
- {
- Component c = getComponent();
- return (c != null) ? c.getLocale() : Session.get().getLocale();
- }
-
/**
* Gets the server time zone. Override this method if you want to fix to a certain time zone,
* regardless of what actual time zone the server is in.
diff --git a/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/basic/DateLabel.java b/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/basic/DateLabel.java
index e4a4c9afa4d..550bfed2798 100644
--- a/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/basic/DateLabel.java
+++ b/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/basic/DateLabel.java
@@ -233,7 +233,6 @@ public DateLabel(String id, IModel model, DateConverter converter)
{
throw new IllegalStateException("converter may not be null");
}
- converter.setComponent(this);
this.converter = converter;
}
diff --git a/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java b/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java
index d555b6ac129..682cc2a6ba4 100644
--- a/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java
+++ b/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java
@@ -202,7 +202,6 @@ public DateTextField(String id, IModel model, DateConverter converter)
super(id, model, Date.class);
Args.notNull(converter, "converter");
- converter.setComponent(this);
this.converter = converter;
}
@@ -240,6 +239,7 @@ public IConverter getConverter(Class clazz)
/**
* @see org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat()
*/
+ @Override
public final String getTextFormat()
{
return converter.getDatePattern(getLocale());