ruby-concurrency/thread_safe

View on GitHub

Showing 329 of 329 total issues

Method attempt_internal_replace has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def attempt_internal_replace(key, expected_old_value, hash, current_table, i, node, node_hash)
Severity: Major
Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 50 mins to fix

    Method attempt_get_and_set has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def attempt_get_and_set(key, value, hash, current_table, i, node, node_hash)
    Severity: Major
    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 50 mins to fix

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

                  else if (SIZE_CTRL_UPDATER.compareAndSet(this, sc, -1)) {
                      try {
                          if (table == tab) {
                              table = rebuild(tab);
                              sc = (n << 1) - (n >>> 1);
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2092..2101
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2130..2139
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2084..2093

      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 60.

      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 4 locations. Consider refactoring.
      Open

                      UNSAFE.compareAndSwapInt(this, sizeCtlOffset, sc, -1)) {
                  try {
                      if (tab == table) {
                          table = rebuild(tab);
                          sc = (n << 1) - (n >>> 1);
      Severity: Major
      Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java and 3 other locations - About 50 mins to fix
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2130..2139
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2084..2093
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2122..2131

      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 60.

      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 4 locations. Consider refactoring.
      Open

                  else if (UNSAFE.compareAndSwapInt(this, sizeCtlOffset, sc, -1)) {
                      try {
                          if (table == tab) {
                              table = rebuild(tab);
                              sc = (n << 1) - (n >>> 1);
      Severity: Major
      Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java and 3 other locations - About 50 mins to fix
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2092..2101
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2084..2093
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2122..2131

      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 60.

      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 (size >= (long)(MAXIMUM_CAPACITY >>> 1))
                      n = MAXIMUM_CAPACITY;
                  else {
                      int sz = (int)size;
                      n = tableSizeFor(sz + (sz >>> 1) + 1);
      Severity: Minor
      Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java and 1 other location - About 50 mins to fix
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 3394..3399

      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 60.

      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 4 locations. Consider refactoring.
      Open

                      SIZE_CTRL_UPDATER.compareAndSet(this, sc, -1)) {
                  try {
                      if (tab == table) {
                          table = rebuild(tab);
                          sc = (n << 1) - (n >>> 1);
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2092..2101
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2130..2139
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2122..2131

      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 60.

      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 (size >= (long)(MAXIMUM_CAPACITY >>> 1))
                      n = MAXIMUM_CAPACITY;
                  else {
                      int sz = (int)size;
                      n = tableSizeFor(sz + (sz >>> 1) + 1);
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 3402..3407

      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 60.

      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

              public final void remove() {
                  Object k = nextKey;
                  if (k == null && (advance() == null || (k = nextKey) == null))
                      throw new IllegalStateException();
                  map.internalReplace(k, null, null);
      Severity: Minor
      Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java and 1 other location - About 50 mins to fix
      ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2490..2495

      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 59.

      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

              public final void remove() {
                  Object k = nextKey;
                  if (k == null && (advance() == null || (k = nextKey) == null))
                      throw new IllegalStateException();
                  map.internalReplace(k, null, null);
      ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2498..2503

      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 59.

      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 deeply nested control flow statements.
      Open

                                          if (count >= TREE_THRESHOLD)
                                              replaceWithTreeBin(tab, i, k);
      Severity: Major
      Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                                if (count >= TREE_THRESHOLD)
                                                    replaceWithTreeBin(tab, i, k);
        Severity: Major
        Found in ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                      if ((pr = p.right) != null && h >= pr.hash && (r = getTreeNode(h, k, pr)) != null)
                                          return r;
                                      // try to continue iterating on the left side
                                      else if ((pl = p.left) != null && h <= pl.hash)
                                          dir = -1;
          Severity: Major
          Found in ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        if (!collide && q != null && q.hash == p.hash)
                                            collide = true;
            Severity: Major
            Found in ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                          if ((pr = p.right) != null && h >= pr.hash && (r = getTreeNode(h, k, pr)) != null)
                                              return r;
                                          // try to continue iterating on the left side
                                          else if ((pl = p.left) != null && h <= pl.hash)
                                              dir = -1;
              Severity: Major
              Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                                    if ((p.val = v) == null) {
                                                        deleted = true;
                                                        t.deleteTreeNode(p);
                                                    }
                Severity: Major
                Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if (busy == 0 && casBusy()) {
                                              boolean created = false;
                                              try {               // Recheck under lock
                                                  Cell[] rs; int m, j;
                                                  if ((rs = cells) != null &&
                  Severity: Major
                  Found in ext/org/jruby/ext/thread_safe/jsr166e/Striped64.java - About 45 mins to fix

                    Method writeObject has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        @SuppressWarnings("unchecked") private void writeObject(java.io.ObjectOutputStream s)
                                throws java.io.IOException {
                            if (segments == null) { // for serialization compatibility
                                segments = (Segment<K,V>[])
                                        new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
                    Severity: Minor
                    Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 45 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Avoid deeply nested control flow statements.
                    Open

                                                if ((pr = p.right) != null && h >= pr.hash && (r = getTreeNode(h, k, pr)) != null)
                                                    return r;
                                                else // continue descending down the left subtree
                                                    dir = -1;
                    Severity: Major
                    Found in ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java - About 45 mins to fix

                      Method compare_and_set has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                                  def compare_and_set(old_value, new_value)
                                    return false unless @___mutex.try_lock
                                    begin
                                      return false unless @___value.equal? old_value
                                      @___value = new_value
                      Severity: Minor
                      Found in lib/thread_safe/util/atomic_reference.rb - About 45 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Severity
                      Category
                      Status
                      Source
                      Language