Program: 8636
Project: 8636
Buggy source:
@Override public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState){
  setHasOptionsMenu(true);
  View view=inflater.inflate(R.layout.fragment_compass,container,false);
  Context context=getContext();
  Coordinate coordinate=Utils.getCoordinate(getContext());
  if (coordinate == null) {
    Utils.setActivityTitleAndSubtitle(getActivity(),getString(R.string.compass),"String_Node_Str");
  }
 else {
    Utils.setActivityTitleAndSubtitle(getActivity(),getString(R.string.qibla_compass),Utils.getCityName(context,true));
  }
  compassListener=new SensorEventListener(){
    static final float ALPHA=0.15f;
    float azimuth;
    @Override public void onAccuracyChanged(    Sensor sensor,    int accuracy){
    }
    @Override public void onSensorChanged(    SensorEvent event){
      float angle=event.values[0];
      if (stop)       angle=0;
      azimuth=lowPass(angle,azimuth);
      compassView.setBearing(azimuth);
      compassView.invalidate();
    }
    /** 
 * https://en.wikipedia.org/wiki/Low-pass_filter#Algorithmic_implementation http://developer.android.com/reference/android/hardware/SensorEvent.html#values
 */
    private float lowPass(    float input,    float output){
      if (Math.abs(180 - input) > 170) {
        return input;
      }
      return output + ALPHA * (input - output);
    }
  }
;
  compassView=view.findViewById(R.id.compass_view);
  DisplayMetrics displayMetrics=new DisplayMetrics();
  getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
  int width=displayMetrics.widthPixels;
  int height=displayMetrics.heightPixels;
  compassView.setScreenResolution(width,height - 2 * height / 8);
  if (coordinate != null) {
    compassView.setLongitude(coordinate.getLongitude());
    compassView.setLatitude(coordinate.getLatitude());
    compassView.initCompassView();
    compassView.invalidate();
  }
  sensorManager=(SensorManager)getContext().getSystemService(Context.SENSOR_SERVICE);
  sensor=sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
  if (sensor != null) {
    sensorManager.registerListener(compassListener,sensor,SensorManager.SENSOR_DELAY_FASTEST);
  }
 else {
    Toast.makeText(context,getString(R.string.compass_not_found),Toast.LENGTH_SHORT).show();
  }
  return view;
}

Fixed version (ground truth):
@Override public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState){
  setHasOptionsMenu(true);
  View view=inflater.inflate(R.layout.fragment_compass,container,false);
  Context context=getContext();
  Coordinate coordinate=Utils.getCoordinate(getContext());
  if (coordinate == null) {
    Utils.setActivityTitleAndSubtitle(getActivity(),getString(R.string.compass),"String_Node_Str");
  }
 else {
    Utils.setActivityTitleAndSubtitle(getActivity(),getString(R.string.qibla_compass),Utils.getCityName(context,true));
  }
  compassListener=new SensorEventListener(){
    static final float ALPHA=0.15f;
    float azimuth;
    @Override public void onAccuracyChanged(    Sensor sensor,    int accuracy){
    }
    @Override public void onSensorChanged(    SensorEvent event){
      float angle=event.values[0];
      if (stop)       angle=0;
      azimuth=lowPass(angle,azimuth);
      compassView.setBearing(azimuth);
      compassView.invalidate();
    }
    /** 
 * https://en.wikipedia.org/wiki/Low-pass_filter#Algorithmic_implementation http://developer.android.com/reference/android/hardware/SensorEvent.html#values
 */
    private float lowPass(    float input,    float output){
      if (Math.abs(180 - input) > 170) {
        return input;
      }
      return output + ALPHA * (input - output);
    }
  }
;
  compassView=view.findViewById(R.id.compass_view);
  setCompassMetrics();
  if (coordinate != null) {
    compassView.setLongitude(coordinate.getLongitude());
    compassView.setLatitude(coordinate.getLatitude());
    compassView.initCompassView();
    compassView.invalidate();
  }
  sensorManager=(SensorManager)getContext().getSystemService(Context.SENSOR_SERVICE);
  sensor=sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
  if (sensor != null) {
    sensorManager.registerListener(compassListener,sensor,SensorManager.SENSOR_DELAY_FASTEST);
  }
 else {
    Toast.makeText(context,getString(R.string.compass_not_found),Toast.LENGTH_SHORT).show();
  }
  return view;
}