Skip to content

Commit 8ecc02e

Browse files
committed
GROOVY-11874: add null check
1 parent 09773c0 commit 8ecc02e

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/main/java/groovy/lang/MetaClassImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
import java.util.function.BiConsumer;
113113

114114
import static groovy.lang.Tuple.tuple;
115-
import static java.lang.Character.isUpperCase;
116115
import static org.apache.groovy.ast.tools.ClassNodeUtils.isValidAccessorName;
117116
import static org.apache.groovy.util.Arrays.concat;
118117
import static org.codehaus.groovy.ast.tools.GeneralUtils.inSamePackage;
@@ -2170,7 +2169,9 @@ private Tuple2<MetaMethod, MetaProperty> createMetaMethodAndMetaProperty(final C
21702169
MetaMethod mm = null;
21712170
MetaProperty mp = getMetaProperty(sender, name, useSuper, isStatic);
21722171

2173-
if ((mp == null || mp instanceof CachedField) && !name.isEmpty() && isUpperCase(name.charAt(0)) && (name.length() < 2 || !isUpperCase(name.charAt(1))) && !"Class".equals(name) && !"MetaClass".equals(name)) {
2172+
if ((mp == null || mp instanceof CachedField)
2173+
&& name != null && !name.isEmpty() && Character.isUpperCase(name.charAt(0)) // GROOVY-11874
2174+
&& (name.length() == 1 || (!Character.isUpperCase(name.charAt(1)) && !name.equals("Class") && !name.equals("MetaClass"))) ) {
21742175
// GROOVY-9618: adjust because capitalised properties aren't stored as meta bean props
21752176
MetaProperty saved = mp;
21762177
mp = getMetaProperty(sender, BeanUtils.decapitalize(name), useSuper, isStatic);

src/test/groovy/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,16 @@ class ArraysAndCollectionsSTCTest extends StaticTypeCheckingTestCase {
10731073
'''
10741074
}
10751075

1076+
// GROOVY-11874
1077+
@Test
1078+
void testMapGetAt() {
1079+
assertScript '''
1080+
String name = null
1081+
def map = [:]
1082+
map[name]
1083+
'''
1084+
}
1085+
10761086
// GROOVY-6266
10771087
@Test
10781088
void testMapGenerics() {

0 commit comments

Comments
 (0)