Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-10330

JdbcTestUtils readScript fails to see commented lines with tabs

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.1.4
    • Fix Version/s: None
    • Component/s: Data:JDBC, Test
    • Labels:
    • Last commented by a User:
      true

      Description

      Spring failed to parse SQL script when some lines are comments with tabs before comments markers.

      For example for the file :

      	-- My comment
      My SQL INSERT STATEMENT;
      

      This will generate the following statement

      	-- My comment My SQL INSERT STATEMENT;
      

      And throw the following exception on execution :

      org.hibernate.exception.GenericJDBCException: Type SQL non valide: sqlKind = UNINITIALIZED
      	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
      	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      	at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
      	at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
      	at $Proxy53.executeUpdate(Unknown Source)
      	at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:509)
      	at org.springframework.jdbc.core.JdbcTemplate$1UpdateStatementCallback.doInStatement(JdbcTemplate.java:1)
      	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396)
      	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:519)
      	at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:252)
      	at org.springframework.test.jdbc.SimpleJdbcTestUtils.executeSqlScript(SimpleJdbcTestUtils.java:150)
      	at org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests.executeSqlScript(AbstractTransactionalJUnit4SpringContextTests.java:141)
      [...]
      

      My guess for the fix would be to add trim on the following statement :
      JdbcTestUtils.java, readScript(LineNumberReader lineNumberReader, String commentPrefix), Line 257:

      if (StringUtils.hasText(currentStatement) && (commentPrefix != null && !currentStatement.trim().startsWith(commentPrefix))) {
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sbrannen Sam Brannen
              Reporter:
              lschoelens Laurent S.
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 31 weeks, 3 days ago