ruby-concurrency/thread_safe

View on GitHub

Showing 329 of 329 total issues

Method initialize_table has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize_table
      until current_table ||= table
        if (size_ctrl = size_control) == NOW_RESIZING
          Thread.pass # lost initialization race; just spin
        else
Severity: Minor
Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr 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

Method toArray has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        @SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) {
            long sz = map.mappingCount();
            if (sz > (long)(MAX_ARRAY_SIZE))
                throw new OutOfMemoryError(oomeMsg);
            int m = (int)sz;

    Method toArray has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            @SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) {
                long sz = map.mappingCount();
                if (sz > (long)(MAX_ARRAY_SIZE))
                    throw new OutOfMemoryError(oomeMsg);
                int m = (int)sz;
    Severity: Minor
    Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 1 hr to fix

      Method attempt_compute has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def attempt_compute(key, hash, current_table, i, node, node_hash)
            added = false
            current_table.try_lock_via_hash(i, node, node_hash) do
              predecessor_node = nil
              while true
      Severity: Minor
      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

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

                            for (int i = 0; i < tab.length(); ++i) {
                                int c = 0;
                                for (Node e = tabAt(tab, i); e != null; e = e.next) {
                                    if (++c > TREE_THRESHOLD &&
                                            (e.key instanceof Comparable)) {
        ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 3435..3444

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

        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

                            for (int i = 0; i < tab.length; ++i) {
                                int c = 0;
                                for (Node e = tabAt(tab, i); e != null; e = e.next) {
                                    if (++c > TREE_THRESHOLD &&
                                            (e.key instanceof Comparable)) {
        ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 3427..3436

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

        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 boolean containsValue(Object value) {
                if (value == null)
                    throw new NullPointerException();
                Object v;
                Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
        ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2713..2723

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

        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 boolean containsValue(Object value) {
                if (value == null)
                    throw new NullPointerException();
                Object v;
                Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
        ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2721..2731

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

        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

        Method getTreeNode has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                @SuppressWarnings("unchecked") final TreeNode getTreeNode
                (int h, RubyObject k, TreeNode p) {
                    RubyClass c = k.getMetaClass(); boolean kNotComparable = !k.respondsTo("<=>");
                    while (p != null) {
                        int dir, ph;  RubyObject pk; RubyClass pc;
        Severity: Minor
        Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 1 hr to fix

          Method tryAwaitLock has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  final void tryAwaitLock(AtomicReferenceArray<Node> tab, int i) {
                      if (tab != null && i >= 0 && i < tab.length()) { // sanity check
                          int r = ThreadLocalRandom.current().nextInt(); // randomize spins
                          int spins = MAX_SPINS, h;
                          while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) {

            Method tryAwaitLock has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    final void tryAwaitLock(Node[] tab, int i) {
                        if (tab != null && i >= 0 && i < tab.length) { // sanity check
                            int r = ThreadLocalRandom.current().nextInt(); // randomize spins
                            int spins = MAX_SPINS, h;
                            while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) {
            Severity: Minor
            Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 1 hr to fix

              Method getTreeNode has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      @SuppressWarnings("unchecked") final TreeNode getTreeNode
                      (int h, RubyObject k, TreeNode p) {
                          RubyClass c = k.getMetaClass(); boolean kNotComparable = !k.respondsTo("<=>");
                          while (p != null) {
                              int dir, ph;  RubyObject pk; RubyClass pc;

                Method clear has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def clear
                      return self unless current_table = table
                      current_table_size = current_table.size
                      deleted_count = i = 0
                      while i < current_table_size
                Severity: Minor
                Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

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

                                      if ((e = tabAt(t, i)) != null && e.hash == MOVED) {
                                          if ((ek = e.key) instanceof TreeBin)
                                              e = ((TreeBin)ek).first;
                                          else {
                                              tab = (AtomicReferenceArray<Node>)ek;
                  ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2482..2489

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

                  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 ((e = tabAt(t, i)) != null && e.hash == MOVED) {
                                          if ((ek = e.key) instanceof TreeBin)
                                              e = ((TreeBin)ek).first;
                                          else {
                                              tab = (Node[])ek;
                  ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2474..2481

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

                  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 int hashCode() {
                          int h = 0;
                          Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
                          Object v;
                          while ((v = it.advance()) != null) {
                  Severity: Minor
                  Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java and 1 other location - About 55 mins to fix
                  ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 3139..3147

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

                  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 int hashCode() {
                          int h = 0;
                          Traverser<K,V,Object> it = new Traverser<K,V,Object>(this);
                          Object v;
                          while ((v = it.advance()) != null) {
                  ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 3147..3155

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

                  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

                          for (Node p = e.next; p != null; p = p.next) {
                              int b = p.hash & bit;
                              if (b != runBit) {
                                  runBit = b;
                                  lastRun = p;
                  ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 2256..2262

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

                  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

                          for (Node p = e.next; p != null; p = p.next) {
                              int b = p.hash & bit;
                              if (b != runBit) {
                                  runBit = b;
                                  lastRun = p;
                  Severity: Minor
                  Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java and 1 other location - About 55 mins to fix
                  ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 2248..2254

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

                  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

                  Method get_or_default has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_or_default(key, else_value = nil)
                        hash          = key_hash(key)
                        current_table = table
                        while current_table
                          node = current_table.volatile_get_by_hash(hash)
                  Severity: Minor
                  Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 55 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