From fc373ee96f6bbecdf8c29a679da8fcaa0b260a86 Mon Sep 17 00:00:00 2001 From: Andrey Subbotin Date: Tue, 12 Jul 2016 16:55:56 +0400 Subject: [PATCH] PL-7428 StackOverflowError in ScheduledExecution.toString() --- .../core/app/scheduling/SchedulingTest.java | 5 ++++ .../cuba/core/entity/ScheduledExecution.java | 10 ------- .../cuba/core/entity/ScheduledTask.java | 27 ++++++++++++------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/core/test/com/haulmont/cuba/core/app/scheduling/SchedulingTest.java b/modules/core/test/com/haulmont/cuba/core/app/scheduling/SchedulingTest.java index 635eed2a8e..66dda3b199 100644 --- a/modules/core/test/com/haulmont/cuba/core/app/scheduling/SchedulingTest.java +++ b/modules/core/test/com/haulmont/cuba/core/app/scheduling/SchedulingTest.java @@ -20,7 +20,9 @@ package com.haulmont.cuba.core.app.scheduling; import com.haulmont.cuba.core.entity.ScheduledTask; import com.haulmont.cuba.core.entity.SchedulingType; import com.haulmont.cuba.core.global.TimeSource; +import com.haulmont.cuba.testsupport.TestContainer; import junit.framework.Assert; +import org.junit.ClassRule; import org.junit.Test; import java.text.ParseException; @@ -36,6 +38,9 @@ public class SchedulingTest { private SimpleDateFormat simpleDateFormat; + @ClassRule + public static TestContainer cont = TestContainer.Common.INSTANCE; + public SchedulingTest() { simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT-0")); diff --git a/modules/global/src/com/haulmont/cuba/core/entity/ScheduledExecution.java b/modules/global/src/com/haulmont/cuba/core/entity/ScheduledExecution.java index a6ca8967da..90fcd39696 100644 --- a/modules/global/src/com/haulmont/cuba/core/entity/ScheduledExecution.java +++ b/modules/global/src/com/haulmont/cuba/core/entity/ScheduledExecution.java @@ -98,14 +98,4 @@ public class ScheduledExecution extends BaseUuidEntity { return (finishTime.getTime() - startTime.getTime()) / 1000; } - - @Override - public String toString() { - return "ScheduledExecution{" + - "task=" + task + - ", host='" + server + '\'' + - ", startTime=" + startTime + - (finishTime != null ? ", finishTime=" : "") + - '}'; - } } \ No newline at end of file diff --git a/modules/global/src/com/haulmont/cuba/core/entity/ScheduledTask.java b/modules/global/src/com/haulmont/cuba/core/entity/ScheduledTask.java index 4667e7f51d..0964729bad 100644 --- a/modules/global/src/com/haulmont/cuba/core/entity/ScheduledTask.java +++ b/modules/global/src/com/haulmont/cuba/core/entity/ScheduledTask.java @@ -17,12 +17,13 @@ package com.haulmont.cuba.core.entity; +import com.google.common.base.MoreObjects; import com.haulmont.bali.util.Dom4j; import com.haulmont.chile.core.annotations.MetaProperty; import com.haulmont.chile.core.annotations.NamePattern; import com.haulmont.cuba.core.app.scheduled.MethodParameterInfo; import com.haulmont.cuba.core.entity.annotation.SystemLevel; -import org.apache.commons.lang.BooleanUtils; +import com.haulmont.cuba.core.global.PersistenceHelper; import org.apache.commons.lang.StringUtils; import org.dom4j.Document; import org.dom4j.DocumentHelper; @@ -32,6 +33,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Transient; +import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -39,7 +41,6 @@ import java.util.List; /** * Entity that stores an information about a scheduled task. - * */ @Entity(name = "sys$ScheduledTask") @Table(name = "SYS_SCHEDULED_TASK") @@ -435,13 +436,21 @@ public class ScheduledTask extends BaseUuidEntity implements Creatable, Updatabl @Override public String toString() { - return "ScheduledTask{" + - id + ", " + - beanName + '.' + methodName + - (BooleanUtils.isTrue(singleton) ? ", singleton" : "") + - ", period=" + period + - (startDate != null ? ", startDate=" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(startDate) : "") + - '}'; + MoreObjects.ToStringHelper builder = MoreObjects.toStringHelper("ScheduledTask") + .omitNullValues() + .addValue(id); + String[] fields = new String[]{"beanName", "methodName", "className", "scriptName", "singleton", "period", "cron", "startDate"}; + for (String field : fields) { + if (PersistenceHelper.isLoaded(this, field)) { + Object value = getValue(field); + if (value instanceof Date) { + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + value = df.format(value); + } + builder.add(field, value); + } + } + return builder.toString(); } @MetaProperty