Skip to content

Commit f28ee99

Browse files
committed
Fix empty string indexing of Doctrine repository class; "THashSet contract violation - 25 reports & coming" #985
1 parent 8e170f1 commit f28ee99

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

src/fr/adrienbrault/idea/symfony2plugin/doctrine/DoctrineUtil.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ private static String getAnnotationRepositoryClass(@NotNull PhpDocTag phpDocTag,
153153
String text = phpDocAttributeList.getText();
154154
Matcher matcher = Pattern.compile("repositoryClass\\s*=\\s*\"([^\"]*)\"").matcher(text);
155155
if (matcher.find()) {
156-
return matcher.group(1);
156+
String value = matcher.group(1);
157+
if(StringUtils.isBlank(value)) {
158+
return null;
159+
}
160+
161+
return value;
157162
}
158163

159164
// repositoryClass=Foobar::class
@@ -201,7 +206,13 @@ private static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull
201206
continue;
202207
}
203208

204-
String repositoryClass = YamlHelper.getYamlKeyValueAsString(yamlKey, "repositoryClass");
209+
String repositoryClassValue = YamlHelper.getYamlKeyValueAsString(yamlKey, "repositoryClass");
210+
211+
// check blank condition
212+
String repositoryClass = null;
213+
if(StringUtils.isNotBlank(repositoryClassValue)) {
214+
repositoryClass = repositoryClassValue;
215+
}
205216

206217
// fine repositoryClass exists a valid metadata file
207218
if(!iAmMetadataFile && repositoryClass != null) {

src/fr/adrienbrault/idea/symfony2plugin/doctrine/dict/DoctrineModel.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public DoctrineModel(@NotNull String clazz) {
2323
this.clazz = clazz;
2424
}
2525

26+
public DoctrineModel(@NotNull String clazz, @Nullable String repositoryClass) {
27+
this.clazz = clazz;
28+
this.repositoryClass = repositoryClass;
29+
}
30+
2631
@NotNull
2732
public String getClassName() {
2833
return this.clazz;
@@ -33,18 +38,21 @@ public String getRepositoryClass() {
3338
return repositoryClass;
3439
}
3540

36-
public DoctrineModel setRepositoryClass(@Nullable String repositoryClass) {
37-
this.repositoryClass = repositoryClass;
38-
return this;
39-
}
40-
4141
@Override
4242
public int hashCode() {
43-
return new HashCodeBuilder()
44-
.append(this.clazz)
45-
.append(this.repositoryClass)
46-
.toHashCode()
47-
;
43+
HashCodeBuilder hash = new HashCodeBuilder()
44+
.append(this.clazz);
45+
46+
String repositoryClass = this.repositoryClass;
47+
48+
// null != ""
49+
if(repositoryClass == null) {
50+
repositoryClass = "null";
51+
}
52+
53+
hash.append(repositoryClass);
54+
55+
return hash.toHashCode();
4856
}
4957

5058
@Override

src/fr/adrienbrault/idea/symfony2plugin/stubs/indexes/DoctrineMetadataFileStubIndex.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public Map<String, DoctrineModelSerializable> map(@NotNull FileContent fileConte
5454
if(first == null || first.length() == 0) {
5555
continue;
5656
}
57-
map.put(first, new DoctrineModel(first).setRepositoryClass(pair.getSecond()));
57+
58+
map.put(first, new DoctrineModel(first, pair.getSecond()));
5859
}
5960

6061
return map;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fr.adrienbrault.idea.symfony2plugin.tests.doctrine.dict;
2+
3+
import fr.adrienbrault.idea.symfony2plugin.doctrine.dict.DoctrineModel;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
/**
8+
* @author Daniel Espendiller <daniel@espendiller.net>
9+
*/
10+
public class DoctrineModelTest extends Assert {
11+
@Test
12+
public void testObjectEqualsCheck() {
13+
assertTrue(new DoctrineModel("foobar").equals(new DoctrineModel("foobar")));
14+
assertEquals(new DoctrineModel("foobar").hashCode(), new DoctrineModel("foobar").hashCode());
15+
16+
assertFalse(new DoctrineModel("foobar").equals(new DoctrineModel("foobar", "foo")));
17+
assertNotEquals(new DoctrineModel("foobar").hashCode(), new DoctrineModel("foobar", "foo").hashCode());
18+
19+
assertTrue(new DoctrineModel("foobar", "apple").equals(new DoctrineModel("foobar", "apple")));
20+
assertEquals(new DoctrineModel("foobar", "apple").hashCode(), new DoctrineModel("foobar", "apple").hashCode());
21+
22+
assertFalse(new DoctrineModel("foobar", null).equals(new DoctrineModel("foobar", "")));
23+
assertNotEquals(new DoctrineModel("foobar", null).hashCode(), new DoctrineModel("foobar", "").hashCode());
24+
assertNotEquals(new DoctrineModel("foobar", "").hashCode(), new DoctrineModel("foobar", null).hashCode());
25+
assertNotEquals(new DoctrineModel("foobar", "").hashCode(), new DoctrineModel("foobar").hashCode());
26+
}
27+
}

0 commit comments

Comments
 (0)