Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit d74cce4

Browse files
committed
Merge branch 'master' of ssh://llg00ana.uk.oracle.com:29418/jersey
2 parents 9fdb7e3 + 49a2ff9 commit d74cce4

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

core-common/src/main/java/org/glassfish/jersey/internal/util/ReflectionHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,9 @@ public static boolean isGetter(final Method method) {
905905
&& Modifier.isPublic(method.getModifiers())) {
906906
final String methodName = method.getName();
907907

908-
if (methodName.startsWith("get")) {
908+
if (methodName.startsWith("get") && methodName.length() > 3) {
909909
return !void.class.equals(method.getReturnType());
910-
} else if (methodName.startsWith("is")) {
910+
} else if (methodName.startsWith("is") && methodName.length() > 2) {
911911
return boolean.class.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType());
912912
}
913913
}

core-common/src/test/java/org/glassfish/jersey/internal/util/ReflectionHelperTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.security.PrivilegedAction;
4747

4848
import org.junit.Test;
49+
4950
import static org.hamcrest.CoreMatchers.is;
5051
import static org.hamcrest.CoreMatchers.nullValue;
5152
import static org.hamcrest.MatcherAssert.assertThat;
@@ -187,4 +188,47 @@ public void testGetFromStringStringMethodNegative() throws Exception {
187188

188189
assertThat("Invalid valueOf method found.", methodPA.run(), nullValue());
189190
}
191+
192+
public static class IsGetterTester {
193+
194+
public int get() {
195+
return 0;
196+
}
197+
198+
public boolean is() {
199+
return true;
200+
}
201+
202+
public int getSomething() {
203+
return 0;
204+
}
205+
206+
public boolean isSomething() {
207+
return true;
208+
}
209+
}
210+
211+
@Test
212+
public void testIsGetterWithGetOnlyNegative() throws Exception {
213+
assertThat("isGetter should have returned false for method named 'get'",
214+
ReflectionHelper.isGetter(IsGetterTester.class.getMethod("get")), is(false));
215+
}
216+
217+
@Test
218+
public void testIsGetterWithIsOnlyNegative() throws Exception {
219+
assertThat("isGetter should have returned false for method named 'is'",
220+
ReflectionHelper.isGetter(IsGetterTester.class.getMethod("is")), is(false));
221+
}
222+
223+
@Test
224+
public void testIsGetterWithRealGetterPositive() throws Exception {
225+
assertThat("isGetter should have returned true for method named 'getSomething'",
226+
ReflectionHelper.isGetter(IsGetterTester.class.getMethod("getSomething")), is(true));
227+
}
228+
229+
@Test
230+
public void testIsGetterWithRealIsPositive() throws Exception {
231+
assertThat("isGetter should have returned true for method named 'isSomething'",
232+
ReflectionHelper.isGetter(IsGetterTester.class.getMethod("isSomething")), is(true));
233+
}
190234
}

0 commit comments

Comments
 (0)