itachi1706/SingBuses

View on GitHub

Showing 108 of 112 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            BusStatus status = (state == StaticVariables.CUR) ? busObj.getCurrentBus() :
                    (state == StaticVariables.NEXT) ? busObj.getNextBus() : busObj.getSubsequentBus();
app/src/main/java/com/itachi1706/busarrivalsg/RecyclerViews/BusServiceRecyclerAdapter.java on lines 277..278

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            if (latitude == 0 && longitude == 0) {
                new AlertDialog.Builder(activity).setTitle("Bus Service in Depot")
                        .setMessage("The Bus Service is currently still in the depot so no location can be obtained!")
                        .setPositiveButton("Close", null).show();
                return;
app/src/main/java/com/itachi1706/busarrivalsg/RecyclerViews/BusServiceRecyclerAdapter.java on lines 304..309

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            BusArrivalArrayObjectEstimate status = (state == StaticVariables.CUR) ? busObj.getNextBus() :
                    (state == StaticVariables.NEXT) ? busObj.getNextBus2() : busObj.getNextBus3();
app/src/main/java/com/itachi1706/busarrivalsg/RecyclerViews/FavouritesRecyclerAdapter.java on lines 338..339

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    private static class UnavailableButton implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(v.getContext()).setTitle(R.string.dialog_title_bus_timing_unavailable)
app/src/main/java/com/itachi1706/busarrivalsg/RecyclerViews/BusServiceRecyclerAdapter.java on lines 257..265

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            if (latitude == 0 && longitude == 0) {
                new AlertDialog.Builder(activity).setTitle("Bus Service in Depot")
                        .setMessage("The Bus Service is currently still in the depot so no location can be obtained!")
                        .setPositiveButton("Close", null).show();
                return;
app/src/main/java/com/itachi1706/busarrivalsg/RecyclerViews/FavouritesRecyclerAdapter.java on lines 364..369

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    private static class UnavailableButton implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(v.getContext()).setTitle(R.string.dialog_title_bus_timing_unavailable)
app/src/main/java/com/itachi1706/busarrivalsg/RecyclerViews/FavouritesRecyclerAdapter.java on lines 320..328

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Avoid too many return statements within this method.
Open

        return true

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                    try {
                        tmpJSON = gson.fromJson(data, BusStopJSON[].class);
                    }catch (JsonSyntaxException e) {
                        Toast.makeText(context, "An error occurred parsing public bus stops. Please try again later", Toast.LENGTH_LONG).show();
                        return;
    app/src/main/java/com/itachi1706/busarrivalsg/NTUBusActivity.java on lines 291..296

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 40.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Avoid too many return statements within this method.
    Open

            } else if (other.services != null) return false

      Avoid too many return statements within this method.
      Open

              } else if (other.storage != null) return false

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                        try {
                            busObjsArr = gson.fromJson(data, BusArrivalMain[].class);
                        } catch (JsonSyntaxException e) {
                            Toast.makeText(context, "An error occurred parsing public buses. Please try again later", Toast.LENGTH_LONG).show();
                            return;
        app/src/main/java/com/itachi1706/busarrivalsg/NTUBusActivity.java on lines 257..262

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 40.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Avoid too many return statements within this method.
        Open

                } else if (other.value != null) return false

          Avoid too many return statements within this method.
          Open

                  return true

            Avoid too many return statements within this method.
            Open

                    return true

              Avoid too many return statements within this method.
              Open

                          if (!services.contentEquals(other.services)) return false

                Avoid too many return statements within this method.
                Open

                        if (currentTime != other.currentTime) return false

                  Return an empty collection instead of null.
                  Open

                              return null;

                  Returning null instead of an actual array or collection forces callers of the method to explicitly test for nullity, making them more complex and less readable.

                  Moreover, in many cases, null is used as a synonym for empty.

                  Noncompliant Code Example

                  public static List<Result> getResults() {
                    return null;                             // Noncompliant
                  }
                  
                  public static Result[] getResults() {
                    return null;                             // Noncompliant
                  }
                  
                  public static void main(String[] args) {
                    Result[] results = getResults();
                  
                    if (results != null) {                   // Nullity test required to prevent NPE
                      for (Result result: results) {
                        /* ... */
                      }
                    }
                  }
                  

                  Compliant Solution

                  public static List<Result> getResults() {
                    return Collections.emptyList();          // Compliant
                  }
                  
                  public static Result[] getResults() {
                    return new Result[0];
                  }
                  
                  public static void main(String[] args) {
                    for (Result result: getResults()) {
                      /* ... */
                    }
                  }
                  

                  See

                  • CERT, MSC19-C. - For functions that return an array, prefer returning an empty array over a null value
                  • CERT, MET55-J. - Return an empty array or collection instead of a null value for methods that return an array or collection

                  A "NullPointerException" could be thrown; "busStops" is nullable here.
                  Open

                          busStops.setLayoutManager(linearLayoutManager);

                  A reference to null should never be dereferenced/accessed. Doing so will cause a NullPointerException to be thrown. At best, such an exception will cause abrupt program termination. At worst, it could expose debugging information that would be useful to an attacker, or it could allow an attacker to bypass security measures.

                  Note that when they are present, this rule takes advantage of @CheckForNull and @Nonnull annotations defined in JSR-305 to understand which values are and are not nullable except when @Nonnull is used on the parameter to equals, which by contract should always work with null.

                  Noncompliant Code Example

                  @CheckForNull
                  String getName(){...}
                  
                  public boolean isNameEmpty() {
                    return getName().length() == 0; // Noncompliant; the result of getName() could be null, but isn't null-checked
                  }
                  
                  Connection conn = null;
                  Statement stmt = null;
                  try{
                    conn = DriverManager.getConnection(DB_URL,USER,PASS);
                    stmt = conn.createStatement();
                    // ...
                  
                  }catch(Exception e){
                    e.printStackTrace();
                  }finally{
                    stmt.close();   // Noncompliant; stmt could be null if an exception was thrown in the try{} block
                    conn.close();  // Noncompliant; conn could be null if an exception was thrown
                  }
                  
                  private void merge(@Nonnull Color firstColor, @Nonnull Color secondColor){...}
                  
                  public  void append(@CheckForNull Color color) {
                      merge(currentColor, color);  // Noncompliant; color should be null-checked because merge(...) doesn't accept nullable parameters
                  }
                  
                  void paint(Color color) {
                    if(color == null) {
                      System.out.println("Unable to apply color " + color.toString());  // Noncompliant; NullPointerException will be thrown
                      return;
                    }
                    ...
                  }
                  

                  See

                  Add a private constructor to hide the implicit public one.
                  Open

                  public class BusStorage {

                  Utility classes, which are collections of static members, are not meant to be instantiated. Even abstract utility classes, which can be extended, should not have public constructors.

                  Java adds an implicit public constructor to every class which does not define at least one explicitly. Hence, at least one non-public constructor should be defined.

                  Noncompliant Code Example

                  class StringUtils { // Noncompliant
                  
                    public static String concatenate(String s1, String s2) {
                      return s1 + s2;
                    }
                  
                  }
                  

                  Compliant Solution

                  class StringUtils { // Compliant
                  
                    private StringUtils() {
                      throw new IllegalStateException("Utility class");
                    }
                  
                    public static String concatenate(String s1, String s2) {
                      return s1 + s2;
                    }
                  
                  }
                  

                  Exceptions

                  When class contains public static void main(String[] args) method it is not considered as utility class and will be ignored by this rule.

                  Define a constant instead of duplicating this literal " LIKE " 5 times.
                  Open

                          String query = "SELECT * FROM " + TABLE_ITEMS + " WHERE " + BUS_STOP_DESC + " LIKE " + stopName + ";";

                  Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

                  On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

                  Noncompliant Code Example

                  With the default threshold of 3:

                  public void run() {
                    prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
                    execute("action1");
                    release("action1");
                  }
                  
                  @SuppressWarning("all")                            // Compliant - annotations are excluded
                  private void method1() { /* ... */ }
                  @SuppressWarning("all")
                  private void method2() { /* ... */ }
                  
                  public String method3(String a) {
                    System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
                    return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
                  }
                  

                  Compliant Solution

                  private static final String ACTION_1 = "action1";  // Compliant
                  
                  public void run() {
                    prepare(ACTION_1);                               // Compliant
                    execute(ACTION_1);
                    release(ACTION_1);
                  }
                  

                  Exceptions

                  To prevent generating some false-positives, literals having less than 5 characters are excluded.

                  Severity
                  Category
                  Status
                  Source
                  Language