Kuangcp/JavaBase

View on GitHub

Showing 349 of 349 total issues

Method singleThreadMode has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    private static void singleThreadMode() throws InterruptedException {
        Thread normal = new Thread(() -> log.info("normal"));
        normal.setName("normal");
        normal.start();

Severity: Minor
Found in concurrency/src/main/java/thread/InterruptBizDemo.java - 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 handleInput has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  private void handleInput(Selector selector, SelectionKey key) throws IOException {
    if (key.isValid()) {
      if (key.isAcceptable()) {
        // Accept the new connection
        ServerSocketChannel ssc = (ServerSocketChannel) key.channel();
Severity: Minor
Found in network/src/main/java/com/github/kuangcp/nio/EchoNIOServer.java - 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 parseArgs has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    private int parseArgs(String[] args) throws UnknownHostException {
        int base;
        label:
        for (base = 0; base < args.length; base++) {
            switch (args[base]) {

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

    public void run(){
        try{
            br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            ps = new PrintStream(socket.getOutputStream());
            String line = null;

    Method readDataBase has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public void readDataBase() {
            PreparedStatement ps = null;
            Connection cn = null;
            ResultSet rs = null;
    
    
    Severity: Minor
    Found in gui/src/main/java/com/github/kuangcp/tank/util/Saved.java - About 1 hr to fix

      Method readContent has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private void readContent(Selector selector, SelectionKey sk) throws IOException {
          SocketChannel sc = (SocketChannel) sk.channel();
          ByteBuffer buff = ByteBuffer.allocate(1024);
      
          StringBuilder content = new StringBuilder();
      Severity: Minor
      Found in network/src/main/java/com/github/kuangcp/nio/NIOServer.java - About 1 hr to fix

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

                try {
                    // 设置加密模式为AES的CBC模式
                    Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
                    SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
                    // 取密钥的前16字节作为 iv 初始化向量
        Severity: Major
        Found in class/src/main/java/security/aes/wx/WxMsgAESUtil.java and 1 other location - About 1 hr to fix
        class/src/main/java/security/aes/wx/WXBizMsgCrypt.java on lines 117..132

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

        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 {
                    // 设置加密模式为AES的CBC模式
                    Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
                    SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
                    IvParameterSpec iv = new IvParameterSpec(aesKey, 0, 16);
        Severity: Major
        Found in class/src/main/java/security/aes/wx/WXBizMsgCrypt.java and 1 other location - About 1 hr to fix
        class/src/main/java/security/aes/wx/WxMsgAESUtil.java on lines 37..53

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

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

          public int[] sort(int[] data) {
            int[] arr = Arrays.copyOf(data, data.length);
        
            List<List<Integer>> dataList = new ArrayList<>();
            List<Integer> arrs = new ArrayList<>();
        Severity: Minor
        Found in algorithms/src/main/java/com/github/kuangcp/sort/Shell.java - About 1 hr to fix

          Method pushTimeWheel has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private void pushTimeWheel(int seconds) {
                  Map<ChronoUnit, Integer> tempIndex = new HashMap<>(sortedSlots.size());
                  for (int i = 0; i < sortedSlots.size(); i++) {
                      ChronoUnit unit = sortedSlots.get(i);
                      Integer threshold = slots.get(unit);

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

                    for (int i = 0; i < param.getTotal(); i++) {
                        final Param tmpParam = Param.builder().start(i).build();
                        voidCompletableFuture.thenRunAsync(() -> {
                            try {
                                TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextInt(600) + 200);
            concurrency/src/main/java/situation/timoutpool/CreateNewPool.java on lines 31..42

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

            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

                    for (int i = 0; i < param.getTotal(); i++) {
                        final Param tmpParam = Param.builder().start(i).build();
                        pool.execute(() -> {
                            try {
                                TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextInt(600) + 60);
            concurrency/src/main/java/situation/timoutpool/TimeoutFuture.java on lines 24..35

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

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

              void moveA() {
                refreshValueByImage();
            //            log.info("x "+x+" y "+y+" p "+position);
                for (int i = 0; i < ImageBlockMgr.images.size(); i++) {
                  if (ImageBlockMgr.images.get(i).y - 1 == y && ImageBlockMgr.images.get(i).x == x) {
            Severity: Major
            Found in gui/src/main/java/com/github/kuangcp/jigsaw/Move.java and 2 other locations - About 1 hr to fix
            gui/src/main/java/com/github/kuangcp/jigsaw/Move.java on lines 37..49
            gui/src/main/java/com/github/kuangcp/jigsaw/Move.java on lines 70..81

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

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

              void moveS() {
                refreshValueByImage();
            
            //            log.info("x "+x+" y "+y+" p "+position);
                for (int i = 0; i < ImageBlockMgr.images.size(); i++) {
            Severity: Major
            Found in gui/src/main/java/com/github/kuangcp/jigsaw/Move.java and 2 other locations - About 1 hr to fix
            gui/src/main/java/com/github/kuangcp/jigsaw/Move.java on lines 54..65
            gui/src/main/java/com/github/kuangcp/jigsaw/Move.java on lines 70..81

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

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

              void moveD() {
                refreshValueByImage();
            //            log.info("x "+x+" y "+y+" p "+position);
                for (int i = 0; i < ImageBlockMgr.images.size(); i++) {
                  if (ImageBlockMgr.images.get(i).y + 1 == y && ImageBlockMgr.images.get(i).x == x) {
            Severity: Major
            Found in gui/src/main/java/com/github/kuangcp/jigsaw/Move.java and 2 other locations - About 1 hr to fix
            gui/src/main/java/com/github/kuangcp/jigsaw/Move.java on lines 37..49
            gui/src/main/java/com/github/kuangcp/jigsaw/Move.java on lines 54..65

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

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

              private void initLogicButton() {
                txtResult.setEnabled(false);
                txtResult.setEditable(false);
                txtResult.setHorizontalAlignment(SwingConstants.RIGHT);
                txtResult.setBounds(new Rectangle(33, 19, 310, 34));
            Severity: Minor
            Found in gui/src/main/java/com/github/kuangcp/caculator/Calculator.java - About 1 hr to fix

              Method paintComponent has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  @Override
                  protected void paintComponent(Graphics g) {
                      int offset = 4;
                      int r = 5;
                      int chessR = 20;
              Severity: Minor
              Found in gui/src/main/java/com/github/kuangcp/gomoku/ChessBoard.java - About 1 hr to fix

                Method main has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  public static void main(String[] a) {
                    final CountDownLatch firstLatch = new CountDownLatch(1);
                    final CountDownLatch secondLatch = new CountDownLatch(1);
                    // 使用不可变对象
                    final BuildFactory.Builder builder = new BuildFactory.Builder();

                  Method keyPressed has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public void keyPressed(KeyEvent e) {
                          //加了if条件后 实现了墙的限制(如果是游戏中的道具,该怎么办)
                          if (e.getKeyCode() == KeyEvent.VK_A) {
                              hero.setDirect(2);
                              if (PlayStageMgr.instance.willInBorder(hero))
                  Severity: Minor
                  Found in gui/src/main/java/com/github/kuangcp/tank/v2/MainPanelV2.java - 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 keyPressed has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public void keyPressed(KeyEvent e) {
                          //加了if条件后 实现了墙的限制(如果是游戏中的道具,该怎么办)
                          if (e.getKeyCode() == KeyEvent.VK_A) {
                              hero.setDirect(2);
                              if ((hero.getX() - 10) > 0)
                  Severity: Minor
                  Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java - 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

                  Severity
                  Category
                  Status
                  Source
                  Language