groovy
  1. groovy
  2. GROOVY-5393

groovy.lang.MissingMethodException: No signature of method: java.lang.String.positive()

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
    • Environment:
      windows xp
    • Number of attachments :
      0

      Description

      Hi,

      If I put the "+" in the new line when I try to concatenate String/GString I got groovy.lang.MissingMethodException

      def test = "Hello"
      +"World"

      produce the following exception:
      groovy.lang.MissingMethodException: No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
      Possible solutions: notify(), size(), size(), tokenize(), tokenize()
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unaryPlus(ScriptBytecodeAdapter.java:764)
      at com.cwh.aladdinslegacy.actions.ReplayActionBeanTest.groovyTest(ReplayActionBeanTest.groovy:37)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:182)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

      Process finished with exit code -1

      I saw the similar problem by googling it. So I thought it is already been fixed, but apparently it is not fixed the version 1.8.0 up

      Can you take a look into it since it's blocking the release of our product.
      Thank you very much

        Activity

        Hide
        Paul King added a comment - - edited

        That syntax isn't supported. You can either join the two lines or use a "\" at the end of the first line, or at least have the "+" on the same line, or use a multi-line String. Lookahead is done for dots, so ".plus('World')" on the second line would be ok.

        Show
        Paul King added a comment - - edited That syntax isn't supported. You can either join the two lines or use a "\" at the end of the first line, or at least have the "+" on the same line, or use a multi-line String. Lookahead is done for dots, so ".plus('World')" on the second line would be ok.
        Hide
        blackdrag blackdrag added a comment -

        As per Paul's comment I close the issue as "Won't Fix". If you did mean something else, than the mere syntax issue, then feel free to reopen the issue or leave an comment

        Show
        blackdrag blackdrag added a comment - As per Paul's comment I close the issue as "Won't Fix". If you did mean something else, than the mere syntax issue, then feel free to reopen the issue or leave an comment
        Hide
        Paul King added a comment -

        Just as a final comment, if you really did need that syntax you could roll your own support with some tricky metaprogramming or AST manipulation though the earlier mentioned supported options will be much easier.

        Show
        Paul King added a comment - Just as a final comment, if you really did need that syntax you could roll your own support with some tricky metaprogramming or AST manipulation though the earlier mentioned supported options will be much easier.
        Hide
        Tony Trung Thanh Vo added a comment -

        Hi guys, I looked around and I saw your reasoning for not adding "+" at the beginning of the new line

        "The reason why we don't support that is because it is not clear to the compiler what it means. With having to have a semicolon as line ending, the parser can know the expression does not end till the semi is reached and therefore put everything in the expression, even if there a re new lines. Actually new lines in an expression don't have all that much a meaning to the parser in Java. In Groovy a new line can terminate an expression and on top of that most expressions can be used where you would normally use a statement. +x is valid on its own, therefore in Groovy we cannot know if putting a +x on the next line belongs to the line before or not. We decided for having the style with the operator on the line before as a guide to ensure there will be no problem and that works. You can also use \ at then end to help the parser. But since there is no general working solution without this helping there won't be ever support for this unless a grammar change is made, that makes this case no longer having multiple meanings."

        I would agree that it's hard for you guys to do it ... However, you guys have made so much effort in making groovy a friendly language to java, and this "+" is such a basic syntax in java, I wonder if you guys could let me know if you guys thinking of putting the support for the syntax in the near future like less than 3 months

        Show
        Tony Trung Thanh Vo added a comment - Hi guys, I looked around and I saw your reasoning for not adding "+" at the beginning of the new line "The reason why we don't support that is because it is not clear to the compiler what it means. With having to have a semicolon as line ending, the parser can know the expression does not end till the semi is reached and therefore put everything in the expression, even if there a re new lines. Actually new lines in an expression don't have all that much a meaning to the parser in Java. In Groovy a new line can terminate an expression and on top of that most expressions can be used where you would normally use a statement. +x is valid on its own, therefore in Groovy we cannot know if putting a +x on the next line belongs to the line before or not. We decided for having the style with the operator on the line before as a guide to ensure there will be no problem and that works. You can also use \ at then end to help the parser. But since there is no general working solution without this helping there won't be ever support for this unless a grammar change is made, that makes this case no longer having multiple meanings." I would agree that it's hard for you guys to do it ... However, you guys have made so much effort in making groovy a friendly language to java, and this "+" is such a basic syntax in java, I wonder if you guys could let me know if you guys thinking of putting the support for the syntax in the near future like less than 3 months
        Hide
        Paul King added a comment -

        It's not just a question of whether it is hard or not. Firstly, Groovy possibly has better ways of supporting what you are trying to do. Why not use multi-line Strings? Secondly, it was a decision made a while ago and changing it now could potentially break existing scripts/code. People can use the positive and negative methods in DSLs, e.g.

        use(MovieRating) {
          name = 'The Spy Who Loved Me'
          audience = '18+'
          +"action packed"
          -"a little long"
        }
        

        Would currently call: setName, setAudience, positive, negative.
        After such a change it would call just the first two plus some string concatenations.

        Show
        Paul King added a comment - It's not just a question of whether it is hard or not. Firstly, Groovy possibly has better ways of supporting what you are trying to do. Why not use multi-line Strings? Secondly, it was a decision made a while ago and changing it now could potentially break existing scripts/code. People can use the positive and negative methods in DSLs, e.g. use(MovieRating) { name = 'The Spy Who Loved Me' audience = '18+' + "action packed" - "a little long " } Would currently call: setName, setAudience, positive, negative. After such a change it would call just the first two plus some string concatenations.

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Tony Trung Thanh Vo
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: