Derby
  1. Derby
  2. DERBY-693

Incorrect line number in the error message when parser throws syntax error in some specific examples

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 10.2.1.6
    • Fix Version/s: None
    • Component/s: SQL
    • Urgency:
      Normal
    • Issue & fix info:
      Known fix, Newcomer, Repro attached

      Description

      After connecting to a database through ij, parser returns correct line number for the sql "select" the first time around but it returns incorrect line number when the same sql is rexecuted, as shown below
      $ java org.apache.derby.tools.ij
      ij version 10.2
      ij> connect 'jdbc:derby:c:/dellater/db1';
      ij> select
      ;
      ERROR 42X01: Syntax error: Encountered "<EOF>" at line 1, column 8.
      ij> select
      ;
      ERROR 42X01: Syntax error: Encountered "<EOF>" at line 2, column 8.
      ij>

      This is caused by UCode_CharStream's UpdateLineColumn method. When the sql "select" is executed the first time, the parser comes to UpdateLineColumn method for trailing \r and then for trailing \n for the first line "select". The trailing \n causes the prevCharIsLF to be set to true. Since this sql is incorrect by itself, parser will throw a syntax error. After the exception and before the processing of next sql "select", this prevCharIsLF flag does not get set to false(this is the problem). When the first character "s" is read, UpdateLineColumn checks if prevCharIsLF set to true and if yes, it increments(incorrectly) the line number to 2 and that is why the second time around, execution of "select" gives syntax error at line 2 rather than line 1.

      This also causes problem with the optimizer hints when they are used in incorrect context as shown below.
      $ java org.apache.derby.tools.ij
      ij version 10.2
      ij> connect 'jdbc:derby:c:/dellater/db1';
      ij> – derby-properties
      select * from t1;
      ERROR 42X01: Syntax error: Encountered "derby-properties" at line 1, column 4.
      ij> – derby-properties
      select * from t1;
      ERROR 42X01: Syntax error: Encountered "derby-properties" at line 2, column 4.

      1. w.sql
        0.1 kB
        Rick Hillegas

        Activity

        Hide
        Daniel John Debrunner added a comment -

        Seems like a minor issue to me, maybe even a trivial one.

        Show
        Daniel John Debrunner added a comment - Seems like a minor issue to me, maybe even a trivial one.
        Hide
        Rick Hillegas added a comment -

        Attaching repro, w.sql.

        Show
        Rick Hillegas added a comment - Attaching repro, w.sql.
        Hide
        Rick Hillegas added a comment -

        Triaged for 10.5.3: assigned normal urgency, marked as "known fix", "newcomer", and "repro attached".

        Show
        Rick Hillegas added a comment - Triaged for 10.5.3: assigned normal urgency, marked as "known fix", "newcomer", and "repro attached".
        Hide
        Leshan Bashitha Wijegunawardana added a comment -

        I'm a computer engineering undergraduate who is new to the Apache Derby code base. According to the explanation here I understood that this issue can be overcome by setting prevCharIsLF flag to false before calling UpdateLineColumn method. When I go through the UCode_CharStream class there is one place that the UpdateLineColumn method is called. That is in the readChar method. So I hope this can be overcome by setting prevCharIsLF flag to false before calling UpdateLineColumn method in the readChar method. Is that ok? Else can anyone explain me the issue liittle bit.
        Thanks.

        Show
        Leshan Bashitha Wijegunawardana added a comment - I'm a computer engineering undergraduate who is new to the Apache Derby code base. According to the explanation here I understood that this issue can be overcome by setting prevCharIsLF flag to false before calling UpdateLineColumn method. When I go through the UCode_CharStream class there is one place that the UpdateLineColumn method is called. That is in the readChar method. So I hope this can be overcome by setting prevCharIsLF flag to false before calling UpdateLineColumn method in the readChar method. Is that ok? Else can anyone explain me the issue liittle bit. Thanks.
        Hide
        Amelia Garripoli added a comment -

        Thank you for your email. This is an automated reply. I don't work during summer term and will be available again on September 2, 2016.

        If you are seeking advising, please contact the Advising & Counseling Center, Room HSS-203G on the Bremerton campus. The primary Entry Advisor for all CIS programs is Steve Quinn (squinn@olympic.edu). To make an advising appointment contact him directly or call the Advising & Counseling Center at 360-475-7530. Additional information about CIS programs and the BAS-IS program can be found at the CIS "Digital Advisor" at http://cis2.oc.ctc.edu/oc_apps/CIS/da/cisadvisor.php

        If you need immediate assistance on anything else, please contact the Business & Technology division office at 360-475-7360.

        See you in September,
        ~Amelia.

        Amelia Garripoli, Professor, Information Systems
        Olympic College, 1600 Chester Avenue, Bremerton, WA 98337
        agarripoli@olympic.edu, (360) 475-7588, TEC-210
        http://faculty.olympic.edu/agarripoli
        See OC's Bachelor of Applied Science in Information Systems (BAS IS)


        "A world without string is chaos." ~ Rudolf Smuntz, MouseHunt

        Show
        Amelia Garripoli added a comment - Thank you for your email. This is an automated reply. I don't work during summer term and will be available again on September 2, 2016. If you are seeking advising, please contact the Advising & Counseling Center, Room HSS-203G on the Bremerton campus. The primary Entry Advisor for all CIS programs is Steve Quinn (squinn@olympic.edu). To make an advising appointment contact him directly or call the Advising & Counseling Center at 360-475-7530. Additional information about CIS programs and the BAS-IS program can be found at the CIS "Digital Advisor" at http://cis2.oc.ctc.edu/oc_apps/CIS/da/cisadvisor.php If you need immediate assistance on anything else, please contact the Business & Technology division office at 360-475-7360. See you in September, ~Amelia. Amelia Garripoli, Professor, Information Systems Olympic College, 1600 Chester Avenue, Bremerton, WA 98337 agarripoli@olympic.edu, (360) 475-7588, TEC-210 http://faculty.olympic.edu/agarripoli See OC's Bachelor of Applied Science in Information Systems (BAS IS) — "A world without string is chaos." ~ Rudolf Smuntz, MouseHunt
        Hide
        Bryan Pendleton added a comment -

        I think you're definitely looking at the right code.

        I encourage you to test your theory about a possible fix:

        1) First, run the IJ statements as described in the bug description, so that
        you can see the behavior that happens

        2) Next, try making the change that you think will fix it

        3) Then, try the same IJ experiment, with your modified code. Does it
        resolve the problem?

        Let us know what you see when you make these experiments.

        Show
        Bryan Pendleton added a comment - I think you're definitely looking at the right code. I encourage you to test your theory about a possible fix: 1) First, run the IJ statements as described in the bug description, so that you can see the behavior that happens 2) Next, try making the change that you think will fix it 3) Then, try the same IJ experiment, with your modified code. Does it resolve the problem? Let us know what you see when you make these experiments.
        Hide
        Leshan Bashitha Wijegunawardana added a comment -

        Bryan, I did all the above mentioned steps. But it didn't resolve. When the sql command("select") is executed prevCharIsLF flag is set to true in both the occasions even without modification to the code. In both the occasions UpdateLineColumn method is called and the code within the if block(which is checking prevCharIsLF is true ) is executed. (incrementing line number is also here) But for the surprise when giving the error message line number is given as in the description every time. When I did the modification mentioned above (prevCharIsLF is set to false before calling UpdateLineColumn method in readChar method) , since prevCharIsLF is set to false the code within the if block is not executed which means that incrementing line number is also not executed. But even after that also the error message is as above. And also even after commenting the line incrementing part also gives the error message as in the description. So it seems like incrementing line number incorrectly happens not within the code which is in the description.

        Show
        Leshan Bashitha Wijegunawardana added a comment - Bryan, I did all the above mentioned steps. But it didn't resolve. When the sql command("select") is executed prevCharIsLF flag is set to true in both the occasions even without modification to the code. In both the occasions UpdateLineColumn method is called and the code within the if block(which is checking prevCharIsLF is true ) is executed. (incrementing line number is also here) But for the surprise when giving the error message line number is given as in the description every time. When I did the modification mentioned above (prevCharIsLF is set to false before calling UpdateLineColumn method in readChar method) , since prevCharIsLF is set to false the code within the if block is not executed which means that incrementing line number is also not executed. But even after that also the error message is as above. And also even after commenting the line incrementing part also gives the error message as in the description. So it seems like incrementing line number incorrectly happens not within the code which is in the description.
        Hide
        Bryan Pendleton added a comment -

        OK, that is good analysis and good to know.

        Sometimes, our first guess about the source of the problem is wrong.

        We will have to look some more.

        I see that the UCode_CharStream class also contains the interesting methods "adjustBeginLineColumn()" and "ReInit()". Perhaps one of those methods is being called, and is altering the line number unexpectedly?

        Perhaps you can instrument each of the places where the 'line' field of the class is being changed, and observe how the changes occur, when you run the reproduction script?

        Show
        Bryan Pendleton added a comment - OK, that is good analysis and good to know. Sometimes, our first guess about the source of the problem is wrong. We will have to look some more. I see that the UCode_CharStream class also contains the interesting methods "adjustBeginLineColumn()" and "ReInit()". Perhaps one of those methods is being called, and is altering the line number unexpectedly? Perhaps you can instrument each of the places where the 'line' field of the class is being changed, and observe how the changes occur, when you run the reproduction script?
        Hide
        Leshan Bashitha Wijegunawardana added a comment -

        Bryan, I tried with commenting all the line incrementing parts with the 'line' field. But it doesn't give any change for the line number in the error message giving. Error message is giving always at line 2 for the second select. I tried with giving '0' for the line field in the class which is originally given as line = 1. But then also no change. I hope that line number is incrementing wrongly is not directly in this piece of code.

        Show
        Leshan Bashitha Wijegunawardana added a comment - Bryan, I tried with commenting all the line incrementing parts with the 'line' field. But it doesn't give any change for the line number in the error message giving. Error message is giving always at line 2 for the second select. I tried with giving '0' for the line field in the class which is originally given as line = 1. But then also no change. I hope that line number is incrementing wrongly is not directly in this piece of code.

          People

          • Assignee:
            Leshan Bashitha Wijegunawardana
            Reporter:
            Mamta A. Satoor
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:

              Development