ruby-concurrency/thread_safe

View on GitHub

Showing 329 of 329 total issues

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

                try {                        // needed in case equals() throws
                    if (tabAt(tab, i) == f) {
                        count = 1;
                        for (Node e = f;; ++count) {
                            Object ek, ev;
ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 1428..1454

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

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 rebuild has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private static final Node[] rebuild(Node[] tab) {
        int n = tab.length;
        Node[] nextTab = new Node[n << 1];
        Node fwd = new Node(MOVED, nextTab, null, null);
        int[] buffer = null;       // holds bins to revisit; null until needed
Severity: Major
Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 3 hrs to fix

    Method rebuild has 94 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static final AtomicReferenceArray<Node> rebuild(AtomicReferenceArray<Node> tab) {
            int n = tab.length();
            AtomicReferenceArray<Node> nextTab = new AtomicReferenceArray<Node>(n << 1);
            Node fwd = new Node(MOVED, nextTab, null, null);
            int[] buffer = null;       // holds bins to revisit; null until needed

      Method putTreeNode has 93 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              @SuppressWarnings("unchecked") final TreeNode putTreeNode
              (int h, RubyObject k, Object v) {
                  RubyClass c = k.getMetaClass();
                  boolean kNotComparable = !k.respondsTo("<=>");
                  TreeNode pp = root, p = null;

        Method putTreeNode has 93 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                @SuppressWarnings("unchecked") final TreeNode putTreeNode
                (int h, RubyObject k, Object v) {
                    RubyClass c = k.getMetaClass();
                    boolean kNotComparable = !k.respondsTo("<=>");
                    TreeNode pp = root, p = null;
        Severity: Major
        Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 3 hrs to fix

          JRubyCacheBackend has 30 methods (exceeds 20 allowed). Consider refactoring.
          Open

              @JRubyClass(name="JRubyCacheBackend", parent="Object")
              public static class JRubyCacheBackend extends RubyObject {
                  // Defaults used by the CHM
                  static final int DEFAULT_INITIAL_CAPACITY = 16;
                  static final float DEFAULT_LOAD_FACTOR = 0.75f;
          Severity: Minor
          Found in ext/org/jruby/ext/thread_safe/JRubyCacheBackendLibrary.java - About 3 hrs to fix

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

                        else if ((fh = f.hash) == MOVED) {
                            if ((fk = f.key) instanceof TreeBin) {
                                TreeBin t = (TreeBin)fk;
                                t.acquire(0);
                                try {
            ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 1848..1879

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

            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

                                try {
                                    if (tabAt(tab, i) == f) {
                                        count = 1;
                                        for (Node e = f;; ++count) {
                                            Object ek, ev;
            ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 1521..1546

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

            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

                                try {
                                    if (tabAt(tab, i) == f) {
                                        count = 1;
                                        for (Node e = f;; ++count) {
                                            Object ek, ev;
            ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 1529..1554

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

            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

                        else if ((fh = f.hash) == MOVED) {
                            if ((fk = f.key) instanceof TreeBin) {
                                TreeBin t = (TreeBin)fk;
                                t.acquire(0);
                                try {
            ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 1840..1871

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

            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 internalReplace has 89 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private final Object internalReplace(Object k, Object v, Object cv) {
                    int h = spread(k.hashCode());
                    Object oldVal = null;
                    for (Node[] tab = table;;) {
                        Node f; int i, fh; Object fk;
            Severity: Major
            Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 3 hrs to fix

              Method internalReplace has 89 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private final Object internalReplace(Object k, Object v, Object cv) {
                      int h = spread(k.hashCode());
                      Object oldVal = null;
                      for (AtomicReferenceArray<Node> tab = table;;) {
                          Node f; int i, fh; Object fk;

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

                    public boolean equals(Object o) {
                        if (o != this) {
                            if (!(o instanceof Map))
                                return false;
                            Map<?,?> m = (Map<?,?>) o;
                ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 3189..3211

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

                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 equals(Object o) {
                        if (o != this) {
                            if (!(o instanceof Map))
                                return false;
                            Map<?,?> m = (Map<?,?>) o;
                ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java on lines 3197..3219

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

                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 retry_update has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                      def retry_update(x, hash_code, was_uncontended) # :yields: current_value
                        hash     = hash_code
                        collided = false # True if last slot nonempty
                        while true
                          if current_cells = cells
                Severity: Minor
                Found in lib/thread_safe/util/striped64.rb - About 3 hrs 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 tryAwaitLock has a Cognitive Complexity of 24 (exceeds 5 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 3 hrs 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 tryAwaitLock has a Cognitive Complexity of 24 (exceeds 5 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) {

                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 internalPut has 82 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private final Object internalPut(Object k, Object v) {
                        int h = spread(k.hashCode());
                        int count = 0;
                        for (AtomicReferenceArray<Node> tab = table;;) {
                            int i; Node f; int fh; Object fk;

                  Method internalPut has 82 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private final Object internalPut(Object k, Object v) {
                          int h = spread(k.hashCode());
                          int count = 0;
                          for (Node[] tab = table;;) {
                              int i; Node f; int fh; Object fk;
                  Severity: Major
                  Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 3 hrs to fix

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

                                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) {
                                        if (spins >= 0) {
                    ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java on lines 671..696

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

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language