Skip to content

Commit

Permalink
GROOVY-11376: SC: field write for map-based class
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 14, 2024
1 parent 580aee1 commit b3142a3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,10 @@ public void fallbackAttributeOrPropertySite(final PropertyExpression expression,
}
}
}
if (isOrImplements(receiverType, MAP_TYPE) && !isClassReceiver[0]) {
// GROOVY-6954, GROOVY-11376: for map types, replace "map.foo = ..."
// with "map.put('foo', ...)" if no public or protected field exists
if (!isClassReceiver[0] && isOrImplements(receiverType, MAP_TYPE)
&& Optional.ofNullable(getField(receiverType, name)).filter(f -> f.isPublic() || f.isProtected()).isEmpty()) {
MethodVisitor mv = controller.getMethodVisitor();

// store value in temporary variable
Expand Down
38 changes: 38 additions & 0 deletions src/test/groovy/bugs/Groovy6954.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,44 @@ import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase

final class Groovy6954 extends AbstractBytecodeTestCase {

// GROOVY-11376
void testSetMapDotField() {
assertScript '''import groovy.transform.*
@CompileStatic
class M extends TreeMap<String,String> {
def a
public b
protected c
@PackageScope d
private e
def testThis() {
this.a = 'a'
this.b = 'b'
this.c = 'c'
this.d = 'd'
this.e = 'e'
}
def testThat(M that) {
that.a = 'a'
that.b = 'b'
that.c = 'c'
that.d = 'd'
that.e = 'e'
}
}
def map = new M()
map.testThis()
assert map.isEmpty()
def other = new M()
map.testThat(other)
assert map.isEmpty()
assert other.toString() == '[d:d, e:e]'
'''
}

void testSetMapDotProperty() {
extractionOptions.method = 'put'

Expand Down

1 comment on commit b3142a3

@daniellansun
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Succeeded before, but failed when we reran the Micronaut joint validation build just now.

@sdelamo Do you have any idea how to fix the issue related to Micronaut joint validation build?

io.micronaut.http.client.jdk.SslSpec > bad server ssl cert bad server ssl cert [url: https://revoked.badssl.com/, #4] FAILED (1.5s)

  org.gradle.internal.exceptions.DefaultMultiCauseException: Multiple Failures (6 failures)
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
  	org.spockframework.runtime.WrongExceptionThrownError: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
      at app//org.spockframework.runtime.ErrorInfoCollector.assertEmpty(ErrorInfoCollector.java:32)
      at app//org.spockframework.runtime.IterationNode.execute(IterationNode.java:51)
      at app//org.spockframework.runtime.IterationNode.execute(IterationNode.java:13)
      at app//org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
      at app//org.spockframework.runtime.IterationNode.lambda$around$0(IterationNode.java:67)
      at app//org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunIteration$5(PlatformSpecRunner.java:236)
      at app//org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)
      at app//org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:407)
      at app//org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:390)
      at app//org.spockframework.runtime.PlatformSpecRunner.runIteration(PlatformSpecRunner.java:218)
      at app//org.spockframework.runtime.IterationNode.around(IterationNode.java:67)
      at app//org.spockframework.runtime.IterationNode.around(IterationNode.java:13)
      at app//org.spockframework.runtime.ParameterizedFeatureChildExecutor.execute(ParameterizedFeatureChildExecutor.java:104)
      at app//org.spockframework.runtime.PlatformParameterizedSpecRunner$1.runIteration(PlatformParameterizedSpecRunner.java:72)
      at app//org.spockframework.runtime.extension.IDataDriver.lambda$static$0(IDataDriver.java:37)
      at app//org.spockframework.runtime.PlatformParameterizedSpecRunner.runParameterizedFeature(PlatformParameterizedSpecRunner.java:47)
      at app//org.spockframework.runtime.ParameterizedFeatureNode.execute(ParameterizedFeatureNode.java:40)
      at app//org.spockframework.runtime.ParameterizedFeatureNode.execute(ParameterizedFeatureNode.java:16)
      at app//org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
      at app//org.spockframework.runtime.FeatureNode.lambda$around$0(FeatureNode.java:41)
      at app//org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunFeature$4(PlatformSpecRunner.java:199)
      at app//org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)
      at app//org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:407)
      at app//org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:390)
      at app//org.spockframework.runtime.PlatformSpecRunner.runFeature(PlatformSpecRunner.java:192)
      at app//org.spockframework.runtime.FeatureNode.around(FeatureNode.java:41)
      at app//org.spockframework.runtime.FeatureNode.around(FeatureNode.java:12)
      at java.base@17.0.11/java.util.ArrayList.forEach(ArrayList.java:1511)
      at app//org.spockframework.runtime.SpockNode.sneakyInvoke(SpockNode.java:40)
      at app//org.spockframework.runtime.SpecNode.lambda$around$0(SpecNode.java:63)
      at app//org.spockframework.runtime.PlatformSpecRunner.lambda$createMethodInfoForDoRunSpec$0(PlatformSpecRunner.java:61)
      at app//org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:156)
      at app//org.spockframework.runtime.PlatformSpecRunner.invokeRaw(PlatformSpecRunner.java:407)
      at app//org.spockframework.runtime.PlatformSpecRunner.invoke(PlatformSpecRunner.java:390)
      at app//org.spockframework.runtime.PlatformSpecRunner.runSpec(PlatformSpecRunner.java:55)
      at app//org.spockframework.runtime.SpecNode.around(SpecNode.java:63)
      at app//org.spockframework.runtime.SpecNode.around(SpecNode.java:11)
      at java.base@17.0.11/java.util.ArrayList.forEach(ArrayList.java:1511)
  Caused by: Expected exception of type 'java.lang.RuntimeException', but no exception was thrown
      at app//org.spockframework.lang.SpecInternals.checkExceptionThrown(SpecInternals.java:84)
      at app//org.spockframework.lang.SpecInternals.thrownImpl(SpecInternals.java:71)
      at io.micronaut.http.client.jdk.SslSpec.bad server ssl cert(SslSpec.groovy:29)


Please sign in to comment.