oracle-db-tools icon indicating copy to clipboard operation
oracle-db-tools copied to clipboard

SqlCl CREATE JAVA quote mishandling

Open vic-ita opened this issue 5 years ago • 1 comments

Hi there.

I'm reporting a bug on SqlCl. (Tested on SqlCl version 19.2.1.206.1649 ).

With the statement CREATE JAVA, SqlCl mishandles quotes symbols whenever they are contained in single-line java comments.

I.E.: consinder the following statements:

The following statement will work fine since the quotes appear in an even number

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED MyTestClass AS
 public class MyTestClass {
	 public static String welcome() {
		// it's a comment
		return "Welcome World";
		// it's another comment
	 } 
}
/

On the other hand the following statement will fail since quotes appear in an odd number (just one)

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED MyTestClass AS
 public class MyTestClass {
	 public static String welcome() {
		// it's a comment
		return "Welcome World";
	 } 
}
/

Here is the SqlCl output for the first snippet:

SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED MyTestClass AS
  2   public class MyTestClass {
  3   public static String welcome() {
  4  // it's a comment
  5  return "Welcome World";
  6  // it's another comment
  7   }
  8  }
  9  /

Java Source MYTESTCLASS creato

SQL>

Now look what happens with the same code but with an odd number of single quotes:

SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED MyTestClass AS
  2   public class MyTestClass {
  3   public static String welcome() {
  4  // it's a comment
  5  return "Welcome World";
  6   }
  7  }
  8  /
  9
 10
 11  /
 12
 13
 14  '
 15  /
Errore con inizio alla riga : 1 nel comando -
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED MyTestClass AS
 public class MyTestClass {
 public static String welcome() {
// it's a comment
return "Welcome World";
 }
}
/


/


'
Report error -
ORA-29536: origine di formato errato: Encountered "/" at line 7, column 1.
Was expecting one of:
    <EOF>
    "#sql" ...
    "static" ...
    "abstract" ...
    "final" ...
    "private" ...
    "protected" ...
    "public" ...
    "strictfp" ...
    "class" ...
    "enum" ...
    "interface" ...
    "native" ...
    "synchronized" ...
    "transient" ...
    "volatile" ...
    ";" ...
    "@" ...
    "\\u001a" ...

29536. 00000 -  "badly formed source: %s"
*Cause:    An attempt was made to create a Java source object with text
           that could not be parsed adequately to determine the class(es)
           defined by it.
*Action:   Correct errors in source.
SQL>

Note how the terminator character on line 8 is ignored. Then on line 11 it is ignored a second time (I could have hit it an arbitrary numner of times tho). On line 14 I added another quote "closing" the one opened in the java comment. Thus on line 15 SqlCl recognizes the last terminator character and creates a statement that is clearly invalid for the DB engine.

ALSO, note that the problem ONLY happens when dealing with single line java comments. Consider the following snippet as a proof of this behavior:

SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED MyTestClass AS
  2   public class MyTestClass {
  3   public static String welcome() {
  4   /*
  5  // it's a comment
  6   */
  7  return "Welcome World";
  8   }
  9  }
 10  /

Java Source MYTESTCLASS creato

SQL>

Vincenzo.

vic-ita avatar Oct 03 '19 16:10 vic-ita

bug logged

bamcgill avatar Jan 21 '22 11:01 bamcgill