Skip to content

Commit bf515fc

Browse files
authored
make Project/Group comparison case sensitive (#4017)
fixes #4006
1 parent a3d44b4 commit bf515fc

File tree

4 files changed

+17
-39
lines changed

4 files changed

+17
-39
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Group.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.configuration;
2525

26-
import java.util.Locale;
26+
import java.util.Objects;
2727
import java.util.Set;
2828
import java.util.TreeSet;
2929
import java.util.regex.Pattern;
@@ -252,16 +252,12 @@ public boolean match(String name) {
252252

253253
@Override
254254
public int compareTo(Group o) {
255-
return getName().toUpperCase(Locale.ROOT).compareTo(
256-
o.getName().toUpperCase(Locale.ROOT));
255+
return getName().compareTo(o.getName());
257256
}
258257

259258
@Override
260259
public int hashCode() {
261-
int hash = 3;
262-
hash = 41 * hash + (this.name == null ? 0 :
263-
this.name.toUpperCase(Locale.ROOT).hashCode());
264-
return hash;
260+
return Objects.hashCode(name);
265261
}
266262

267263
@Override
@@ -280,8 +276,7 @@ public boolean equals(Object obj) {
280276
int numNull = (name == null ? 1 : 0) + (other.name == null ? 1 : 0);
281277
switch (numNull) {
282278
case 0:
283-
return name.toUpperCase(Locale.ROOT).equals(
284-
other.name.toUpperCase(Locale.ROOT));
279+
return name.equals(other.name);
285280
case 1:
286281
return false;
287282
default:

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Project.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.io.FileNotFoundException;
2828
import java.io.IOException;
2929
import java.io.Serializable;
30-
import java.util.Locale;
30+
import java.util.Objects;
3131
import java.util.Set;
3232
import java.util.TreeSet;
3333
import java.util.logging.Level;
@@ -585,16 +585,12 @@ public static Project getByName(String name) {
585585

586586
@Override
587587
public int compareTo(Project p2) {
588-
return getName().toUpperCase(Locale.ROOT).compareTo(
589-
p2.getName().toUpperCase(Locale.ROOT));
588+
return getName().compareTo(p2.getName());
590589
}
591590

592591
@Override
593592
public int hashCode() {
594-
int hash = 3;
595-
hash = 41 * hash + (this.name == null ? 0 :
596-
this.name.toUpperCase(Locale.ROOT).hashCode());
597-
return hash;
593+
return Objects.hashCode(name);
598594
}
599595

600596
@Override
@@ -613,8 +609,7 @@ public boolean equals(Object obj) {
613609
int numNull = (name == null ? 1 : 0) + (other.name == null ? 1 : 0);
614610
switch (numNull) {
615611
case 0:
616-
return name.toUpperCase(Locale.ROOT).equals(
617-
other.name.toUpperCase(Locale.ROOT));
612+
return name.equals(other.name);
618613
case 1:
619614
return false;
620615
default:

opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/GroupTest.java

+8-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.configuration;
2424

@@ -39,14 +39,14 @@
3939
import static org.junit.jupiter.api.Assertions.assertSame;
4040
import static org.junit.jupiter.api.Assertions.assertTrue;
4141

42-
public class GroupTest {
42+
class GroupTest {
4343

4444
/**
4545
* Test that a {@code Group} instance can be encoded and decoded without
4646
* errors.
4747
*/
4848
@Test
49-
public void testEncodeDecode() {
49+
void testEncodeDecode() {
5050
// Create an exception listener to detect errors while encoding and
5151
// decoding
5252
final LinkedList<Exception> exceptions = new LinkedList<>();
@@ -79,7 +79,7 @@ public void testEncodeDecode() {
7979
}
8080

8181
@Test
82-
public void invalidPatternTest() {
82+
void invalidPatternTest() {
8383
testPattern("*dangling asterisk", false);
8484
testPattern(".*(", false);
8585
testPattern("+", false);
@@ -102,7 +102,7 @@ private void testPattern(String pattern, boolean valid) {
102102
}
103103

104104
@Test
105-
public void basicTest() {
105+
void basicTest() {
106106
Group g = new Group("Random name", "abcd");
107107

108108
assertEquals("Random name", g.getName());
@@ -140,7 +140,7 @@ public void basicTest() {
140140
}
141141

142142
@Test
143-
public void subgroupsTest() {
143+
void subgroupsTest() {
144144
Group g1 = new Group("Random name", "abcd");
145145
Group g2 = new Group("Random name2", "efgh");
146146
Group g3 = new Group("Random name3", "xyz");
@@ -177,7 +177,7 @@ public void subgroupsTest() {
177177
}
178178

179179
@Test
180-
public void projectTest() {
180+
void projectTest() {
181181
Group random1 = new Group("Random name", "abcd");
182182
Group random2 = new Group("Random name2", "efgh");
183183

@@ -205,19 +205,13 @@ public void projectTest() {
205205
}
206206

207207
@Test
208-
public void testEquality() {
208+
void testEquality() {
209209
Group g1 = new Group();
210210
Group g2 = new Group();
211211
assertEquals(g1, g2, "null == null");
212212

213213
g1 = new Group("name");
214214
g2 = new Group("other");
215215
assertNotEquals(g1, g2, "\"name\" != \"other\"");
216-
217-
g1 = new Group("name");
218-
g2 = new Group("NAME");
219-
assertEquals(g1, g2, "\"name\" == \"NAME\"");
220-
assertEquals(g1, g1, "\"name\" == \"name\"");
221-
assertEquals(g2, g2, "\"NAME\" == \"NAME\"");
222216
}
223217
}

opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/ProjectTest.java

-6
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,6 @@ void testEquality() {
217217
g1 = new Project("name");
218218
g2 = new Project("other");
219219
assertNotEquals(g1, g2, "\"name\" != \"other\"");
220-
221-
g1 = new Project("name");
222-
g2 = new Project("NAME");
223-
assertEquals(g1, g2, "\"name\" == \"NAME\"");
224-
assertEquals(g1, g1, "\"name\" == \"name\"");
225-
assertEquals(g2, g2, "\"NAME\" == \"NAME\"");
226220
}
227221

228222
@Test

0 commit comments

Comments
 (0)