alibaba/transmittable-thread-local

View on GitHub

Showing 86 of 208 total issues

File ConcurrentReferenceHashMap.java has 677 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright 2002-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.

    File TransmittableThreadLocal.java has 419 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    package com.alibaba.ttl;
    
    import edu.umd.cs.findbugs.annotations.NonNull;
    import edu.umd.cs.findbugs.annotations.Nullable;
    import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

      Method nullSafeHashCode has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          public static int nullSafeHashCode(@Nullable Object obj) {
              if (obj == null) {
                  return 0;
              }
              if (obj.getClass().isArray()) {

      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

      ConcurrentReferenceHashMap has 29 methods (exceeds 20 allowed). Consider refactoring.
      Open

      @SuppressWarnings("ALL")
      // Is there a class annotation in FindBugs to ignore all warning in a file
      // https://stackoverflow.com/questions/13398685
      @SuppressFBWarnings
      class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V> {

        Method restructure has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

                private void restructure(boolean allowResize, @Nullable Reference<K, V> ref) {
                    boolean needsResize;
                    lock();
                    try {
                        int countAfterRestructure = this.count.get();

        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

        Transmitter has 24 methods (exceeds 20 allowed). Consider refactoring.
        Open

            public static class Transmitter {
                /**
                 * Capture all {@link TransmittableThreadLocal} and registered {@link ThreadLocal} values in the current thread.
                 *
                 * @return the captured {@link TransmittableThreadLocal} values

          Method arrayEquals has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              private static boolean arrayEquals(Object o1, Object o2) {
                  if (o1 instanceof Object[] && o2 instanceof Object[]) {
                      return Arrays.equals((Object[]) o1, (Object[]) o2);
                  }
                  if (o1 instanceof boolean[] && o2 instanceof boolean[]) {

          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

          File TtlWrappers.java has 265 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          package com.alibaba.ttl;
          
          import com.alibaba.ttl.spi.TtlEnhanced;
          import com.alibaba.ttl.spi.TtlWrapper;
          import edu.umd.cs.findbugs.annotations.NonNull;
          Severity: Minor
          Found in ttl2-compatible/src/main/java/com/alibaba/ttl/TtlWrappers.java - About 2 hrs to fix

            Method restructure has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    private void restructure(boolean allowResize, @Nullable Reference<K, V> ref) {
                        boolean needsResize;
                        lock();
                        try {
                            int countAfterRestructure = this.count.get();

              Method parseLine has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static int parseLine(URL url, BufferedReader reader, int lineNum, LinkedHashSet<String> names) throws IOException {
                      String line = reader.readLine();
                      if (line == null) {
                          return -1;
                      }

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

                  @Override
                  public final void doTransform(@NonNull final ClassInfo classInfo) throws IOException, NotFoundException, CannotCompileException {
                      // work-around ClassCircularityError:
                      //      https://github.com/alibaba/transmittable-thread-local/issues/278
                      //      https://github.com/alibaba/transmittable-thread-local/issues/234

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

                  @Override
                  public final void doTransform(@NonNull final ClassInfo classInfo) throws IOException, NotFoundException, CannotCompileException {
                      // work-around ClassCircularityError:
                      //      https://github.com/alibaba/transmittable-thread-local/issues/278
                      //      https://github.com/alibaba/transmittable-thread-local/issues/234

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

                  private static int parseLine(URL url, BufferedReader reader, int lineNum, LinkedHashSet<String> names) throws IOException {
                      String line = reader.readLine();
                      if (line == null) {
                          return -1;
                      }

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

                  public static int nullSafeHashCode(@Nullable Object obj) {
                      if (obj == null) {
                          return 0;
                      }
                      if (obj.getClass().isArray()) {

                Method transform has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    @Override
                    public final byte[] transform(@Nullable final ClassLoader loader, @Nullable final String classFile, final Class<?> classBeingRedefined,
                                                  final ProtectionDomain protectionDomain, @NonNull final byte[] classFileBuffer) {
                        try {
                            // Lambda has no class file, no need to transform, just return.

                  Method transform has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      @Override
                      public final byte[] transform(@Nullable final ClassLoader loader, @Nullable final String classFile, final Class<?> classBeingRedefined,
                                                    final ProtectionDomain protectionDomain, @NonNull final byte[] classFileBuffer) {
                          try {
                              // Lambda has no class file, no need to transform, just return.
                  Severity: Minor
                  Found in ttl-agent/src/main/java/com/alibaba/ttl3/agent/TtlTransformer.java - About 1 hr to fix

                    Method loadExtensionInstances has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        static <T> Map<ClassLoader, Set<T>> loadExtensionInstances(
                            ClassLoader classLoader, LinkedHashSet<String> instanceClassNames, Class<T> superType,
                            String foundMsgHead, String failLoadMsgHead
                        ) {
                            Map<ClassLoader, Set<T>> ret = new HashMap<>();

                      Method loadExtensionInstances has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          static <T> Map<ClassLoader, Set<T>> loadExtensionInstances(
                                  ClassLoader classLoader, LinkedHashSet<String> instanceClassNames, Class<T> superType,
                                  String foundMsgHead, String failLoadMsgHead
                          ) {
                              Map<ClassLoader, Set<T>> ret = new HashMap<>();

                        Method arrayEquals has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private static boolean arrayEquals(Object o1, Object o2) {
                                if (o1 instanceof Object[] && o2 instanceof Object[]) {
                                    return Arrays.equals((Object[]) o1, (Object[]) o2);
                                }
                                if (o1 instanceof boolean[] && o2 instanceof boolean[]) {

                          Method parseLine has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              private static int parseLine(URL url, BufferedReader reader, int lineNum, LinkedHashSet<String> names) throws IOException {
                                  String line = reader.readLine();
                                  if (line == null) {
                                      return -1;
                                  }
                            Severity
                            Category
                            Status
                            Source
                            Language