diff --git a/src/main/java/io/ebeaninternal/server/profile/UtilLocation.java b/src/main/java/io/ebeaninternal/server/profile/UtilLocation.java index 06aedef6d..7b70dfcb7 100644 --- a/src/main/java/io/ebeaninternal/server/profile/UtilLocation.java +++ b/src/main/java/io/ebeaninternal/server/profile/UtilLocation.java @@ -7,8 +7,19 @@ final class UtilLocation { if (pos == -1) { return shortDescription; } else { - return shortDescription.substring(0, pos); + return trimInit(shortDescription.substring(0, pos)); } } + /** + * Trim constructor init to be "safe" without greater than or less than chars. + */ + private static String trimInit(String desc) { + if (desc.endsWith("")) { + // trim to make a safe label + return desc.substring(0, desc.length() - 6) + "init"; + } + return desc; + } + } diff --git a/src/test/java/io/ebeaninternal/server/profile/UtilLocationTest.java b/src/test/java/io/ebeaninternal/server/profile/UtilLocationTest.java new file mode 100644 index 000000000..1bdbcd2f7 --- /dev/null +++ b/src/test/java/io/ebeaninternal/server/profile/UtilLocationTest.java @@ -0,0 +1,15 @@ +package io.ebeaninternal.server.profile; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class UtilLocationTest { + + @Test + public void label() { + + assertThat(UtilLocation.label("foo")).isEqualTo("foo"); + assertThat(UtilLocation.label("ProfileLocationTest$Other.(ProfileLocationTest.java:47)")).isEqualTo("ProfileLocationTest$Other.init"); + } +} diff --git a/src/test/java/org/tests/profile/ProfileLocationTest.java b/src/test/java/org/tests/profile/ProfileLocationTest.java index 8165a76a0..fccbe8d40 100644 --- a/src/test/java/org/tests/profile/ProfileLocationTest.java +++ b/src/test/java/org/tests/profile/ProfileLocationTest.java @@ -9,6 +9,8 @@ public class ProfileLocationTest { private static ProfileLocation loc = ProfileLocation.create(12, "foo"); + private static ProfileLocation loc2 = ProfileLocation.create(); + private String doIt() { return loc.obtain(); } @@ -16,8 +18,8 @@ public class ProfileLocationTest { @Test public void test_obtain() { - assertThat(doIt()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:13)"); - assertThat(loc.shortDescription()).isEqualTo("ProfileLocationTest.doIt(ProfileLocationTest.java:13)"); + assertThat(doIt()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:15)"); + assertThat(loc.shortDescription()).isEqualTo("ProfileLocationTest.doIt(ProfileLocationTest.java:15)"); assertThat(loc.label()).isEqualTo("ProfileLocationTest.doIt"); } @@ -25,4 +27,21 @@ public class ProfileLocationTest { public void test_add() { loc.add(100); } + + @Test + public void test_constructor() { + + Other other = new Other(); + other.hashCode(); + + assertThat(loc2.label()).isEqualTo("ProfileLocationTest$Other.init"); + assertThat(loc2.shortDescription()).isEqualTo("ProfileLocationTest$Other.(ProfileLocationTest.java:44)"); + } + + static class Other { + + Other() { + loc2.obtain(); + } + } }