Skip to content

Commit 9799df3

Browse files
committed
PropertyOrFieldReference avoids NPE through defensive copy of volatile accessor reference
Issue: SPR-13023
1 parent 0711d6d commit 9799df3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,8 +80,9 @@ public ValueRef getValueRef(ExpressionState state) throws EvaluationException {
8080
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
8181
TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(),
8282
state.getConfiguration().isAutoGrowNullReferences());
83-
if (this.cachedReadAccessor instanceof CompilablePropertyAccessor) {
84-
CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) this.cachedReadAccessor;
83+
PropertyAccessor accessorToUse = this.cachedReadAccessor;
84+
if (accessorToUse instanceof CompilablePropertyAccessor) {
85+
CompilablePropertyAccessor accessor = (CompilablePropertyAccessor) accessorToUse;
8586
this.exitTypeDescriptor = CodeFlow.toDescriptor(accessor.getPropertyType());
8687
}
8788
return tv;
@@ -338,13 +339,18 @@ else if (clazz.isAssignableFrom(targetType)) {
338339

339340
@Override
340341
public boolean isCompilable() {
341-
return (this.cachedReadAccessor instanceof CompilablePropertyAccessor &&
342-
((CompilablePropertyAccessor) this.cachedReadAccessor).isCompilable());
342+
PropertyAccessor accessorToUse = this.cachedReadAccessor;
343+
return (accessorToUse instanceof CompilablePropertyAccessor &&
344+
((CompilablePropertyAccessor) accessorToUse).isCompilable());
343345
}
344346

345347
@Override
346348
public void generateCode(MethodVisitor mv, CodeFlow cf) {
347-
((CompilablePropertyAccessor) this.cachedReadAccessor).generateCode(this.name, mv, cf);
349+
PropertyAccessor accessorToUse = this.cachedReadAccessor;
350+
if (!(accessorToUse instanceof CompilablePropertyAccessor)) {
351+
throw new IllegalStateException("Property accessor is not compilable: " + accessorToUse);
352+
}
353+
((CompilablePropertyAccessor) accessorToUse).generateCode(this.name, mv, cf);
348354
cf.pushDescriptor(this.exitTypeDescriptor);
349355
}
350356

0 commit comments

Comments
 (0)