ANDROID.UF.MEDIAPLAYER
UF (Use Freed) issues are reported when there is an attempt to use resources after they were released. The ANDROID.UF.MEDIAPLAYER warning indicates an attempt to use MediaPlayer after it was released.
Example 1
Copy
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
} catch (IOException e) {
mp.release();
}
mp.start();
mp.release();
return true;
}
return super.onKeyDown(keyCode, event);
}
ANDROID.UF.MEDIAPLAYER is reported for the snippet on line 35 since there is an attempt to use the 'mp' that is released in case of IOException on line 33.
Extension
This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.