Spring Framework
  1. Spring Framework
  2. SPR-7113

Spring Groovy Beans cannot be debugged, because information about source file is lost during bean instantiation

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.0.2
    • Fix Version/s: General Backlog
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      GroovyScriptFactory class is stipping off file information while script class is instantiated:

      this.scriptClass = getGroovyClassLoader().parseClass(scriptSource.getScriptAsString(), scriptSource.suggestedClassName());

      This is a big problem because this code cannot be debugged after this!!!
      However File information can usually be extracted at least from "file:" locations(not sure about classpath

      My proposition is something like this:

      File scriptFile = null;
      if(scriptSource instanceof ResourceScriptSource) {
      Resource resource = ((ResourceScriptSource)scriptSource).getResource();
      if(resource instanceof UrlResource)

      { scriptFile = ((UrlResource)resource).getFile(); }

      }

      //
      if(scriptFile != null)

      { this.scriptClass = getGroovyClassLoader().parseClass(scriptFile); }

      else {
      this.scriptClass = getGroovyClassLoader().parseClass(scriptSource.getScriptAsString(), scriptSource.suggestedClassName());
      }

        Activity

        Hide
        Vladislavs Korehovs added a comment -

        Cleaner solution:

        File scriptFile = null;
        if(scriptSource instanceof ResourceScriptSource)

        { scriptFile = ((ResourceScriptSource)scriptSource).getResource().getFile(); }

        and futhermore instanceof can be replated with behavioral interface: HasResource

        Show
        Vladislavs Korehovs added a comment - Cleaner solution: File scriptFile = null; if(scriptSource instanceof ResourceScriptSource) { scriptFile = ((ResourceScriptSource)scriptSource).getResource().getFile(); } and futhermore instanceof can be replated with behavioral interface: HasResource
        Hide
        Vladislavs Korehovs added a comment -

        You ALSO should parse class like this. Otherwise beans will stop refreshing!!!

        GroovyCodeSource codeSource = new GroovyCodeSource(scriptFile);
        codeSource.setCachable(false);
        this.scriptClass = getGroovyClassLoader().parseClass(codeSource);

        Show
        Vladislavs Korehovs added a comment - You ALSO should parse class like this. Otherwise beans will stop refreshing!!! GroovyCodeSource codeSource = new GroovyCodeSource(scriptFile); codeSource.setCachable(false); this.scriptClass = getGroovyClassLoader().parseClass(codeSource);
        Hide
        Vladislavs Korehovs added a comment -

        Hi,
        it is ridiculous but you still need to call
        scriptSource.getScriptAsString();
        scriptSource.suggestedClassName();
        before calling new version of parseClass(). failure to do so, results on infinite number or attempts to reparse file (modified flag is not reset!!!)

        Show
        Vladislavs Korehovs added a comment - Hi, it is ridiculous but you still need to call scriptSource.getScriptAsString(); scriptSource.suggestedClassName(); before calling new version of parseClass(). failure to do so, results on infinite number or attempts to reparse file (modified flag is not reset!!!)

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Vladislavs Korehovs
            Last updater:
            Trevor Marshall
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Days since last comment:
              3 years, 39 weeks, 1 day ago