Program: 37549
Project: 37549
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  EventBus.getDefault().register(this);
  try {
    ConnectionUtil.initialize(this);
  }
 catch (  Exception e) {
    Toast.makeText(MainActivity.this,R.string.sslFailed,Toast.LENGTH_LONG).show();
  }
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.activity_main);
  PreferenceManager.setDefaultValues(this,R.xml.preferences,false);
  NavigationView navigationView=(NavigationView)findViewById(R.id.nav_view);
  LinearLayout navHeader=(LinearLayout)LayoutInflater.from(this).inflate(R.layout.nav_header_main,null);
  navigationView.addHeaderView(navHeader);
  navigationView.setNavigationItemSelectedListener(this);
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
  mServerConnection=new ServerConnection(this);
  mServerConnection.addConnectionListener(this);
  if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      try {
        mFlashService=new FlashHandler(this,(CameraManager)getSystemService(Context.CAMERA_SERVICE));
      }
 catch (      CameraAccessException|IllegalAccessException e) {
        Log.d("String_Node_Str","String_Node_Str");
      }
    }
    final SurfaceView motionView=((SurfaceView)findViewById(R.id.motionView));
    int scaledSize=getResources().getDimensionPixelSize(R.dimen.motionFontSize);
    MotionVisualizer mv=new MotionVisualizer(motionView,navigationView,prefs,scaledSize);
    boolean newApi=prefs.getBoolean("String_Node_Str",Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
    if (newApi && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      mMotionDetector=new MotionDetectorCamera2(this,(CameraManager)getSystemService(Context.CAMERA_SERVICE),mv,this,mServerConnection);
    }
 else {
      mMotionDetector=new MotionDetector(this,mv,mServerConnection);
    }
  }
  mDiscovery=new ServerDiscovery((NsdManager)getSystemService(Context.NSD_SERVICE));
  if (prefs.getBoolean("String_Node_Str",true)) {
    SharedPreferences.Editor editor1=prefs.edit();
    editor1.putBoolean("String_Node_Str",false);
    editor1.putString("String_Node_Str",BuildConfig.VERSION_NAME);
    editor1.apply();
    final String startText=ResourcesUtil.fetchFirstStart(this);
    UiUtil.showScrollDialog(this,"String_Node_Str",getString(R.string.welcome),startText);
    if (prefs.getString("String_Node_Str","String_Node_Str").isEmpty()) {
      mDiscovery.discover(new ServerDiscovery.DiscoveryListener(){
        @Override public void found(        String serverUrl){
          SharedPreferences.Editor editor1=prefs.edit();
          editor1.putString("String_Node_Str",serverUrl);
          editor1.apply();
        }
        @Override public void notFound(){
        }
      }
,true,true);
    }
  }
 else {
    String lastVersion=prefs.getString("String_Node_Str","String_Node_Str");
    if (!BuildConfig.VERSION_NAME.equals(lastVersion)) {
      SharedPreferences.Editor editor1=prefs.edit();
      editor1.putString("String_Node_Str",BuildConfig.VERSION_NAME);
      editor1.apply();
      final String relText=ResourcesUtil.fetchReleaseNotes(this,lastVersion);
      UiUtil.showScrollDialog(this,getString(R.string.updated),getString(R.string.updatedText),relText);
    }
  }
  mBatteryMonitor=new BatteryMonitor(this,mServerConnection);
  mVolumeMonitor=new VolumeMonitor(this,(AudioManager)getSystemService(Context.AUDIO_SERVICE),mServerConnection);
  mConnectedReporter=new ConnectedIndicator(this,mServerConnection);
  SensorManager m=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
  try {
    mProximityMonitor=new ProximityMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  try {
    mBrightnessMonitor=new BrightnessMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  try {
    mPressureMonitor=new PressureMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  try {
    mTemperatureMonitor=new TemperatureMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  mScreenHandler=new ScreenHandler((PowerManager)getSystemService(POWER_SERVICE),this);
  mCommandQueue=new CommandQueue(mServerConnection);
  mCommandQueue.addHandler(new InternalCommandHandler(this,mServerConnection));
  mCommandQueue.addHandler(new AdminHandler(this));
  mCommandQueue.addHandler(new BluetoothHandler(this,(BluetoothManager)getSystemService(BLUETOOTH_SERVICE)));
  mCommandQueue.addHandler(mScreenHandler);
  mCommandQueue.addHandler(new VolumeHandler(this,(AudioManager)getSystemService(Context.AUDIO_SERVICE)));
  if (mFlashService != null) {
    mCommandQueue.addHandler(mFlashService);
  }
  mRestartCount=getIntent().getIntExtra("String_Node_Str",0);
  showInitialToastMessage(mRestartCount);
  mTextView=navHeader.findViewById(R.id.textView);
  mWebView=((ClientWebView)findViewById(R.id.activity_main_webview));
  mWebView.initialize();
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  EventBus.getDefault().register(this);
  try {
    ConnectionUtil.initialize(this);
  }
 catch (  Exception e) {
    Toast.makeText(MainActivity.this,R.string.sslFailed,Toast.LENGTH_LONG).show();
  }
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.activity_main);
  PreferenceManager.setDefaultValues(this,R.xml.preferences,false);
  NavigationView navigationView=(NavigationView)findViewById(R.id.nav_view);
  LinearLayout navHeader=(LinearLayout)LayoutInflater.from(this).inflate(R.layout.nav_header_main,null);
  navigationView.addHeaderView(navHeader);
  navigationView.setNavigationItemSelectedListener(this);
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
  mServerConnection=new ServerConnection(this);
  mServerConnection.addConnectionListener(this);
  if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      try {
        mFlashService=new FlashHandler(this,(CameraManager)getSystemService(Context.CAMERA_SERVICE));
      }
 catch (      CameraAccessException|IllegalAccessException e) {
        Log.d("String_Node_Str","String_Node_Str");
      }
    }
    final SurfaceView motionView=((SurfaceView)findViewById(R.id.motionView));
    int scaledSize=getResources().getDimensionPixelSize(R.dimen.motionFontSize);
    MotionVisualizer mv=new MotionVisualizer(motionView,navigationView,prefs,scaledSize);
    boolean newApi=prefs.getBoolean("String_Node_Str",Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
    if (newApi && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      mMotionDetector=new MotionDetectorCamera2(this,(CameraManager)getSystemService(Context.CAMERA_SERVICE),mv,this,mServerConnection);
    }
 else {
      mMotionDetector=new MotionDetector(this,mv,mServerConnection);
    }
  }
  mDiscovery=new ServerDiscovery((NsdManager)getSystemService(Context.NSD_SERVICE));
  if (prefs.getBoolean("String_Node_Str",true)) {
    SharedPreferences.Editor editor1=prefs.edit();
    editor1.putBoolean("String_Node_Str",false);
    editor1.putString("String_Node_Str",BuildConfig.VERSION_NAME);
    editor1.apply();
    final String startText=ResourcesUtil.fetchFirstStart(this);
    UiUtil.showScrollDialog(this,"String_Node_Str",getString(R.string.welcome),startText);
    if (prefs.getString("String_Node_Str","String_Node_Str").isEmpty()) {
      mDiscovery.discover(new ServerDiscovery.DiscoveryListener(){
        @Override public void found(        String serverUrl){
          SharedPreferences.Editor editor1=prefs.edit();
          editor1.putString("String_Node_Str",serverUrl);
          editor1.apply();
        }
        @Override public void notFound(){
        }
      }
,true,true);
    }
  }
 else {
    String lastVersion=prefs.getString("String_Node_Str","String_Node_Str");
    if (!BuildConfig.VERSION_NAME.equals(lastVersion)) {
      SharedPreferences.Editor editor1=prefs.edit();
      editor1.putString("String_Node_Str",BuildConfig.VERSION_NAME);
      editor1.apply();
      final String relText=ResourcesUtil.fetchReleaseNotes(this,lastVersion);
      UiUtil.showScrollDialog(this,getString(R.string.updated),getString(R.string.updatedText),relText);
    }
  }
  mBatteryMonitor=new BatteryMonitor(this,mServerConnection);
  mVolumeMonitor=new VolumeMonitor(this,(AudioManager)getSystemService(Context.AUDIO_SERVICE),mServerConnection);
  mConnectedReporter=new ConnectedIndicator(this,mServerConnection);
  SensorManager m=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
  try {
    mProximityMonitor=new ProximityMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  try {
    mBrightnessMonitor=new BrightnessMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  try {
    mPressureMonitor=new PressureMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  try {
    mTemperatureMonitor=new TemperatureMonitor(this,m,mServerConnection);
  }
 catch (  SensorMissingException e) {
    Log.d("String_Node_Str","String_Node_Str");
  }
  ScreenHandler mScreenHandler=new ScreenHandler((PowerManager)getSystemService(POWER_SERVICE),this);
  mCommandQueue=new CommandQueue(this,mServerConnection);
  mCommandQueue.addHandler(new InternalCommandHandler(this,mServerConnection));
  mCommandQueue.addHandler(new AdminHandler(this));
  mCommandQueue.addHandler(new BluetoothHandler(this,(BluetoothManager)getSystemService(BLUETOOTH_SERVICE)));
  mCommandQueue.addHandler(mScreenHandler);
  mCommandQueue.addHandler(new VolumeHandler(this,(AudioManager)getSystemService(Context.AUDIO_SERVICE)));
  if (mFlashService != null) {
    mCommandQueue.addHandler(mFlashService);
  }
  mRestartCount=getIntent().getIntExtra("String_Node_Str",0);
  showInitialToastMessage(mRestartCount);
  mTextView=navHeader.findViewById(R.id.textView);
  mWebView=((ClientWebView)findViewById(R.id.activity_main_webview));
  mWebView.initialize();
}