Scala Programming Language
  1. Scala Programming Language
  2. SI-7253

SQLiteDatabase cannot be closed in Android 4.0 or below devices, in apps built by Scala 2.10.x w/ Android 4.1 due to Scala 2.10.x bytecode problem.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0, Scala 2.10.1
    • Fix Version/s: Scala 2.10.2-RC1
    • Component/s: Build, Developer Tools
    • Labels:
    • Environment:

      Description

      This reports that SQLiteDatabase instance cannot be closed due to "NoSuchMethodError:java.lang.NoSuchMethodError: android.database.sqlite.SQLiteClosable.close" in Android 4.0 or below devices if you build a project by Scala2.10.x with Android 4.1 or above library.
      I believe this is critical problem for all Android developers in Scala.

      ###Whole source codes:

      	class DemoActivity extends Activity{
      	  override def onCreate(savedInstanceState: Bundle) {
          	super.onCreate(savedInstanceState)
      
      	    new SQLHelperDemo(this).getReadableDatabase.close()
      
          	val textView = new TextView(this)
      	    textView.setText("Do I still survive?")
          	setContentView(textView)
        		}
      	}
      	class SQLHelperDemo(context:Context) extends SQLiteOpenHelper(context,"demo",null,1){
      	  def onCreate(p1: SQLiteDatabase) {}
      	  def onUpgrade(p1: SQLiteDatabase, p2: Int, p3: Int) {}
      	}
      

      This seems to come from bytecode differences between Scala 2.10.x and Scala 2.9.x as shown below.

      ###Bytecode extracts
      **[Problem]Scala 2.10.0 android-16(Android4.1) bytecodes:**
      
      	>javap -c DemoActivity
      
      	public void onCreate(android.os.Bundle);
      	...
         	57:aload_2
         	58:invokevirtual#55; //Method android/database/sqlite/SQLiteClosable.close:()V
         	61:return
      	}
      
      **[Working fine]Scala2.10.x with android-15, or Scala2.9.x with android-16 bytecodes:**
      
      	>javap -c DemoActivity
      
      	public void onCreate(android.os.Bundle);
        	...
              57:aload_2
         	58:invokevirtual#55; //Method android/database/sqlite/SQLiteDatabase.close:()V
         	61:return
      	}
      

      Although SQLiteDatabase has "close()" method in all Android version, "close()" is implemented in SQLiteDatabase class until Android 4.0 while it is inherited from SQLiteClosable which is super class of SQLiteDatabase from Android 4.1.

      That's why Scala 2.10.x compiler generates bytecodes with SQLiteClosable.close() which doesn't exist in Android 4.0 or below devices. This leads to "NoSuchMethodError:java.lang.NoSuchMethodError: android.database.sqlite.SQLiteClosable.close".
      Of note, I find a very similar problem in AbsListView.setChoiceMode and there must be more.

      While I'm not sure why this change happens in Scala 2.10.x compiler (maybe ASM difference?), there should be a way to avoid this problem such as compile option.

      You can reproduce this issue from my below github repo, that includes more information in README.

      https://github.com/taisukeoe/scala_2_10_android_error

        Activity

        Hide
        Paul Phillips added a comment -

        Also, I'm absolutely buried in other stuff I have to do. Pull requests extremely welcome.

        Show
        Paul Phillips added a comment - Also, I'm absolutely buried in other stuff I have to do. Pull requests extremely welcome.
        Hide
        Paolo G. Giarrusso added a comment - - edited

        That's the behavior I expected.
        UPDATED: the fix I proposed seems to fix this problem, I need to do some regression testing.

        Show
        Paolo G. Giarrusso added a comment - - edited That's the behavior I expected. UPDATED: the fix I proposed seems to fix this problem, I need to do some regression testing.
        Show
        Paolo G. Giarrusso added a comment - https://github.com/scala/scala/pull/2264
        Hide
        Taisuke Oe added a comment -

        Wow, awesome!! Thank you very much!

        Show
        Taisuke Oe added a comment - Wow, awesome!! Thank you very much!
        Hide
        Paolo G. Giarrusso added a comment -

        The pull request was now merged, so I'm closing this.

        Show
        Paolo G. Giarrusso added a comment - The pull request was now merged, so I'm closing this.

          People

          • Assignee:
            Paolo G. Giarrusso
            Reporter:
            Taisuke Oe
          • Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development