{"action":"closed","issue":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/1291","repository_url":"https://api.github.com/repos/robolectric/robolectric","labels_url":"https://api.github.com/repos/robolectric/robolectric/issues/1291/labels{/name}","comments_url":"https://api.github.com/repos/robolectric/robolectric/issues/1291/comments","events_url":"https://api.github.com/repos/robolectric/robolectric/issues/1291/events","html_url":"https://github.com/robolectric/robolectric/issues/1291","id":44047976,"node_id":"MDU6SXNzdWU0NDA0Nzk3Ng==","number":1291,"title":"NullPointerException when Activity.startActionMode() is called multiple times","user":{"login":"estebanflores","id":8916360,"node_id":"MDQ6VXNlcjg5MTYzNjA=","avatar_url":"https://avatars0.githubusercontent.com/u/8916360?v=4","gravatar_id":"","url":"https://api.github.com/users/estebanflores","html_url":"https://github.com/estebanflores","followers_url":"https://api.github.com/users/estebanflores/followers","following_url":"https://api.github.com/users/estebanflores/following{/other_user}","gists_url":"https://api.github.com/users/estebanflores/gists{/gist_id}","starred_url":"https://api.github.com/users/estebanflores/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/estebanflores/subscriptions","organizations_url":"https://api.github.com/users/estebanflores/orgs","repos_url":"https://api.github.com/users/estebanflores/repos","events_url":"https://api.github.com/users/estebanflores/events{/privacy}","received_events_url":"https://api.github.com/users/estebanflores/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2014-09-26T11:12:58Z","updated_at":"2018-11-05T00:31:27Z","closed_at":"2018-11-05T00:31:27Z","author_association":"NONE","body":"We have troubles to test classes that are currently using activity.startActionMode(). We are using Robolectric 2.2 and the issue appears when there is an interaction between objects with animations. \n\nSee the following test example.\n\n``` java\npackage com.crash.robolectric.test;\n\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.robolectric.Robolectric;\nimport org.robolectric.RobolectricTestRunner;\nimport org.robolectric.util.ActivityController;\n\nimport android.app.Activity;\nimport android.support.v4.app.Fragment;\nimport android.support.v4.app.FragmentActivity;\nimport android.view.ActionMode;\nimport android.view.ActionMode.Callback;\nimport android.view.Menu;\nimport android.view.MenuItem;\nimport android.view.View;\nimport android.view.animation.AnimationUtils;\n\n@RunWith( RobolectricTestRunner.class )\npublic class RobolectrictActionModeTest\n{\n\n   @Test\n   public void crashTest()\n   {\n      final ActivityController<TestActionModeActivity> activityController = Robolectric\n         .buildActivity( TestActionModeActivity.class );\n\n      final TestActionModeActivity activity = activityController.get();\n\n      activityController.create().visible().start();\n\n      startFragmentOnActivity( new Fragment(), activity );\n\n      startAndFinishActionMode( activity );\n      startAndFinishActionMode( activity );\n   }\n\n\n   private void startAndFinishActionMode( final Activity activity )\n   {\n      final ActionMode actionMode = activity.startActionMode( new Callback()\n      {\n\n         @Override\n         public boolean onPrepareActionMode( final ActionMode mode, final Menu menu )\n         {\n            return true;\n         }\n\n         @Override\n         public void onDestroyActionMode( final ActionMode mode )\n         {\n         }\n\n         @Override\n         public boolean onCreateActionMode( final ActionMode mode, final Menu menu )\n         {\n            return true;\n         }\n\n         @Override\n         public boolean onActionItemClicked( final ActionMode mode, final MenuItem item )\n         {\n            return true;\n         }\n      } );\n      actionMode.finish();\n   }\n\n\n   public static void startFragmentOnActivity( final Fragment fragment, final FragmentActivity fragmentActivity )\n   {\n      // Add this fragment to the SupportFragmentManager\n      fragmentActivity\n         .getSupportFragmentManager()\n         .beginTransaction()\n         .add( TestActionModeActivity.PARENT_VIEW_ID, fragment, null )\n         .commit();\n\n      fragment.onViewStateRestored( null );\n   }\n\n   public class CrashFragment extends Fragment\n   {\n      @Override\n      public void onStart()\n      {\n         super.onStart();\n         final View rootView = getActivity().findViewById( android.R.id.content );\n         rootView.setAnimation( AnimationUtils.loadAnimation( getActivity(), android.R.anim.fade_in ) );\n         rootView.animate();\n      }\n   }\n\n}\n\n```\n\n``` java\npackage com.crash.robolectric.test;\n\nimport android.content.Intent;\nimport android.content.ServiceConnection;\nimport android.os.Bundle;\nimport android.support.v4.app.FragmentActivity;\nimport android.widget.FrameLayout;\n\npublic class TestActionModeActivity extends FragmentActivity\n{\n   public TestActionModeActivity()\n   {\n   }\n\n   /** Id of the parent view. */\n   public static final int PARENT_VIEW_ID = 1;\n\n   @Override\n   protected void onCreate( final Bundle savedInstanceState )\n   {\n      setTheme( android.R.style.Theme_Holo );\n      super.onCreate( savedInstanceState );\n      final FrameLayout frameLayout = new FrameLayout( this );\n      frameLayout.setId( PARENT_VIEW_ID );\n      setContentView( frameLayout );\n   }\n\n   @Override\n   public boolean bindService( final Intent service, final ServiceConnection conn, final int flags )\n   {\n      // noop, services not really supported by Robolectric 2.2\n      return false;\n   }\n\n   @Override\n   public void unbindService( final ServiceConnection conn )\n   {\n      // noop, services not really supported by Robolectric 2.2\n   }\n\n}\n\n```\n\nStacktrace of NullPointerException\n\n``` log\njava.lang.NullPointerException\n    at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:390)\n    at android.animation.ValueAnimator.startAnimation(ValueAnimator.java:1031)\n    at android.animation.ValueAnimator.end(ValueAnimator.java:956)\n    at android.animation.AnimatorSet.end(AnimatorSet.java:341)\n    at com.android.internal.widget.ActionBarContextView.finishAnimation(ActionBarContextView.java:271)\n    at com.android.internal.widget.ActionBarContextView.killMode(ActionBarContextView.java:276)\n    at com.android.internal.app.ActionBarImpl.startActionMode(ActionBarImpl.java:444)\n    at android.app.Activity.onWindowStartingActionMode(Activity.java:4801)\n    at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2228)\n    at android.app.Activity.startActionMode(Activity.java:4784)\n    at com.crash.robolectric.test.RobolectrictActionModeTest.startAndFinishActionMode(RobolectrictActionModeTest.java:42)\n    at com.crash.robolectric.test.RobolectrictActionModeTest.crashTest(RobolectrictActionModeTest.java:36)\n    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)\n    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)\n    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)\n    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)\n    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)\n    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)\n    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)\n    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)\n    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)\n    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)\n    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)\n    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175)\n    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)\n    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)\n    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)\n    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)\n    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)\n    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)\n    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)\n\n\n```\n\nIn our real test it crash inside _ShadowObjectAnimator.start()#run_ as workaround we have copied your _ShadowObjectAnimator_ and catching NullpointerExceptions.\n\nIs this Bug already known? \n\nBest Regards\n"}}
{"actor":{"display_login":"jongerrish"}}