title: "No such property: for class: Script1" during using Groovy(String to reflection code)
body: <p>I am trying to use Groovy in order to convert string to the reflection code but I have &quot;No such property&quot; exception.</p>
  <p>I have tried to make global all variables, change the reflection code and put @Field notation but problem still remaining. I put Groovy code inside &quot;runTestSamples()&quot;.</p>
  <h1>MainClass - Test2</h1>
  <pre><code>import java.io.InputStream;
  import java.lang.reflect.InvocationTargetException;
  import java.util.HashMap;
  import java.util.Map;
  
  import org.jacoco.agent.AgentJar;
  import org.jacoco.core.analysis.Analyzer;
  import org.jacoco.core.analysis.CoverageBuilder;
  import org.jacoco.core.analysis.IClassCoverage;
  import org.jacoco.core.data.ExecutionDataStore;
  import org.jacoco.core.data.SessionInfoStore;
  import org.jacoco.core.instr.Instrumenter;
  import org.jacoco.core.runtime.IRuntime;
  import org.jacoco.core.runtime.LoggerRuntime;
  import org.jacoco.core.runtime.RuntimeData;
  
  import groovy.lang.Binding;
  import groovy.lang.GroovyShell;
  
  public class Test2 {
  
      private Runnable targetInstance;
      public Class&lt;?&gt; targetClass;
      private static HashMap&lt;Integer, String&gt; testSamples;
      private static HashMap&lt;String, Integer&gt; coverageData;
      public String targetName;
      public IRuntime runtime;
      public Instrumenter instr;
      public InputStream original;
      public byte[] instrumented;
      public RuntimeData data;
      public MemoryClassLoader memoryClassLoader;
  
      static Test2 t2 = new Test2();
      int a;
  
      public static void main(String[] args) throws Exception {
          testSamples = new HashMap&lt;Integer, String&gt;();
  
          coverageData = new HashMap&lt;String, Integer&gt;();
  
          try {
              t2.execute();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
      public void execute() throws Exception {
          testSamples = new HashMap&lt;Integer, String&gt;();
          coverageData = new HashMap&lt;String, Integer&gt;();
          targetName = SUTClass.class.getName();
          runtime = new LoggerRuntime();
          instr = new Instrumenter(runtime);
          original = getTargetClass(targetName);
          instrumented = instr.instrument(original, targetName);
          original.close();
          data = new RuntimeData();
          runtime.startup(data);
          memoryClassLoader = new MemoryClassLoader();
          memoryClassLoader.addDefinition(targetName, instrumented);
          targetClass = (Class&lt;? extends Runnable&gt;) memoryClassLoader.loadClass(targetName);
          targetInstance = (Runnable) targetClass.newInstance();
          // Test samples
          runTestSamples();
          targetInstance.run();
          final ExecutionDataStore executionData = new ExecutionDataStore();
          final SessionInfoStore sessionInfos = new SessionInfoStore();
          data.collect(executionData, sessionInfos, false);
          runtime.shutdown();
          final CoverageBuilder coverageBuilder = new CoverageBuilder();
          final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
          original = getTargetClass(targetName);
          analyzer.analyzeClass(original, targetName);
          original.close();
  
          for (final IClassCoverage cc : coverageBuilder.getClasses()) {
              coverageData.put(&quot;coveredInstructions&quot;, cc.getInstructionCounter().getCoveredCount());
          }
  
          System.out.println(coverageData.get(&quot;coveredInstructions&quot;));
          System.out.println(a);
  
      }
  
      public static class MemoryClassLoader extends ClassLoader {
          private final Map&lt;String, byte[]&gt; definitions = new HashMap&lt;String, byte[]&gt;();
  
          public void addDefinition(final String name, final byte[] bytes) {
              definitions.put(name, bytes);
          }
  
          @Override
          protected Class&lt;?&gt; loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
              final byte[] bytes = definitions.get(name);
              if (bytes != null) {
                  return defineClass(name, bytes, 0, bytes.length);
              }
              return super.loadClass(name, resolve);
          }
  
      }
  
      private InputStream getTargetClass(final String name) {
          final String resource = '/' + name.replace('.', '/') + &quot;.class&quot;;
          return getClass().getResourceAsStream(resource);
      }
  
      public void runTestSamples() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
              NoSuchMethodException, SecurityException, ClassNotFoundException {
          
          // Test case
          targetClass.getMethod(&quot;f&quot;, int.class, int.class).invoke(targetInstance, 2, 9);
          
          // Groovy String to code
          Binding binding = new Binding();
          GroovyShell shell = new GroovyShell(binding);
          Object value = shell.evaluate(&quot;targetClass.getMethod(\&quot;f\&quot;, int.class, int.class).invoke(targetInstance, 2, 9);&quot;);
  
      }
  
  }
  </code></pre>
  <h1>Exception</h1>
  <pre><code>groovy.lang.MissingPropertyException: No such property: targetClass for class: Script1
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65)
      at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309)
      at Script1.run(Script1.groovy:1)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:437)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:475)
      at groovy.lang.GroovyShell.evaluate(GroovyShell.java:446)
      at Test2.runTestSamples(Test2.java:119)
      at Test2.execute(Test2.java:66)
      at Test2.main(Test2.java:43)
  </code></pre>