Issue2466

classification
Title: No response for script with invalid string
Type: behaviour Severity: major
Components: Core Versions: Jython 2.7
Milestone:
process
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, jamesmudd, ldias, pradeeppanayal, zyasoft
Priority: Keywords:

Created on 2016-02-16.12:06:43 by pradeeppanayal, last changed 2018-03-03.17:52:56 by jeff.allen.

Messages
msg10744 (view) Author: pradeeppanayal (pradeeppanayal) Date: 2016-02-16.12:06:42
Following scripts returns no error/response message on compile or execute using python interceptor.

Test case 1: print "some text      -- Failed
Test case 2: print 'some text      -- Failed
Test case 3: print 'Some data
             #comments / new line / EOF -- Failed 

Failed - Terminates without any error or response.
msg10748 (view) Author: Jim Baker (zyasoft) Date: 2016-02-16.23:48:50
We should be reporting SyntaxError: EOL while scanning string literal
msg11114 (view) Author: Lakshan (ldias) Date: 2017-02-23.00:52:54
Just FYI, this also fails (because it does not raise SyntaxError):

exec('def foo():\n    return "bar\n')

but this works correctly (because it does raise SyntaxError):

exec('a = "bar\n')
msg11119 (view) Author: James Mudd (jamesmudd) Date: 2017-02-23.20:38:33
Could you provide more details on which version of Jython does it fail?

I have just tried this on master and it appears to work almost correctly. Jython returns the correct SyntaxError, with a slightly different message to CPython and the ^ highlighting the position of the error is wrong.

Jython 2.7.1b3 (, Feb 23 2017, 20:19:21) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
Type "help", "copyright", "credits" or "license" for more information.
>>> print "some text
  File "<stdin>", line 1
    print "some text
    ^
SyntaxError: no viable alternative at input '<EOF>'
>>> print 'some text
  File "<stdin>", line 1
    print 'some text
    ^
SyntaxError: no viable alternative at input '<EOF>'
>>> print 'some data
  File "<stdin>", line 1
    print 'some data
    ^
SyntaxError: no viable alternative at input '<EOF>'
>>> exec('def foo():\n    return "bar\n')
>>> exec('a = "bar\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    a = "bar
     ^
SyntaxError: no viable alternative at input '='
>>> 

The only example which actually failed for me (by which I mean incorrectly suceeded) was "exec('def foo():\n    return "bar\n')" where no SyntaxError was raised. I will have a look at that one
msg11120 (view) Author: pradeeppanayal (pradeeppanayal) Date: 2017-02-24.05:06:14
I am using 2.7.0 stand alone jar. Maven,

<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.0</version>
</dependency>

I was using a different version of jython (2.5.3) when I posted that issue.
The issue is still exist in 2.7.0 also.
Test cases,

   - print 'test   -> Failed (No resp and error)
   - print "test'  -> Failed
   - print 'test"  -> Failed
   - print 'test"\nprint 'some valid' -> Success (Getting syntax error)
   - print 'test"\nprint 'some invalid" -> Success (Getting syntax error)

Hope this may help you.

You people had done a great job by implementing this tool. It's really
magical.

Thanks & Regards,
*Pradeep CH*
*+91-7708336299 *

On Fri, Feb 24, 2017 at 2:08 AM, James Mudd <report@bugs.jython.org> wrote:

>
> James Mudd added the comment:
>
> Could you provide more details on which version of Jython does it fail?
>
> I have just tried this on master and it appears to work almost correctly.
> Jython returns the correct SyntaxError, with a slightly different message
> to CPython and the ^ highlighting the position of the error is wrong.
>
> Jython 2.7.1b3 (, Feb 23 2017, 20:19:21)
> [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
> Type "help", "copyright", "credits" or "license" for more information.
> >>> print "some text
>   File "<stdin>", line 1
>     print "some text
>     ^
> SyntaxError: no viable alternative at input '<EOF>'
> >>> print 'some text
>   File "<stdin>", line 1
>     print 'some text
>     ^
> SyntaxError: no viable alternative at input '<EOF>'
> >>> print 'some data
>   File "<stdin>", line 1
>     print 'some data
>     ^
> SyntaxError: no viable alternative at input '<EOF>'
> >>> exec('def foo():\n    return "bar\n')
> >>> exec('a = "bar\n')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<string>", line 1
>     a = "bar
>      ^
> SyntaxError: no viable alternative at input '='
> >>>
>
> The only example which actually failed for me (by which I mean incorrectly
> suceeded) was "exec('def foo():\n    return "bar\n')" where no SyntaxError
> was raised. I will have a look at that one
>
> ----------
> nosy: +jamesmudd
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue2466>
> _______________________________________
>
msg11139 (view) Author: James Mudd (jamesmudd) Date: 2017-02-27.18:56:16
I have looked at this a bit more and have a few more examples which seem strange

>>> print "some text
  File "<stdin>", line 1
    print "some text
    ^
SyntaxError: no viable alternative at input '<EOF>'
>>> exec('print "some text')

>>> exec('print \'some text')

>>> 

print "some text - correctly produces a SyntaxError however exec('print "some text') just prints a blank line like exec('print') would. This behaviour is also reproduced with a escaped single quote.

If you call print('some text') then it always seems to work correctly
>>> print("some text
  File "<stdin>", line 1
    print("some text
        ^
SyntaxError: no viable alternative at input '<EOF>'
>>> print("some text)
  File "<stdin>", line 1
    print("some text)
        ^
SyntaxError: no viable alternative at input '<EOF>'
>>> print("some text")
some text
>>> print('some text
  File "<stdin>", line 1
    print('some text
        ^
SyntaxError: no viable alternative at input '<EOF>'
>>> print('some text)
  File "<stdin>", line 1
    print('some text)
        ^
SyntaxError: no viable alternative at input '<EOF>'
>>> print('some text')
some text
>>> exec('print('some text')')
  File "<stdin>", line 1
    exec('print('some text')')
                ^
SyntaxError: no viable alternative at input 'some'
>>> exec('print(\'some text\')')
some text
>>> exec('print("some text")')
some text
>>>
msg11140 (view) Author: Lakshan (ldias) Date: 2017-02-27.19:23:33
Hi James,

I think that correlates with the way I've been testing: using the 2.7.1b3 maven jar and PythonInterpreter::exec() :

            <dependency>
                <groupId>org.python</groupId>
                <artifactId>jython-standalone</artifactId>
                <version>2.7.1b3</version>
            </dependency>


        PythonInterpreter interp = new PythonInterpreter();
        interp.exec("print \"some text");  # << does not raise SyntaxError, and outputs an empty line
History
Date User Action Args
2018-03-03 17:52:56jeff.allensetmilestone: Jython 2.7.2 ->
2017-02-27 19:23:34ldiassetmessages: + msg11140
2017-02-27 18:56:16jamesmuddsetmessages: + msg11139
2017-02-24 05:13:36pradeeppanayalsetfiles: - unnamed
2017-02-24 05:06:14pradeeppanayalsetfiles: + unnamed
messages: + msg11120
2017-02-23 20:38:34jamesmuddsetnosy: + jamesmudd
messages: + msg11119
2017-02-23 00:52:54ldiassetnosy: + ldias
messages: + msg11114
2016-02-17 16:01:47zyasoftsetmilestone: Jython 2.7.1 -> Jython 2.7.2
2016-02-16 23:48:50zyasoftsetnosy: + fwierzbicki, zyasoft
resolution: accepted
messages: + msg10748
2016-02-16 12:06:43pradeeppanayalcreate