src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java

Summary

Maintainability
D
2 days
Test Coverage

Method generateScratchFile has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    public boolean generateScratchFile(String scratchFileName, String privateKey, int numLayers, int numThreads, int keysPerThread) {
        ArrayList<LamportGenThread> threads = new ArrayList<>(); //ArrayList to hold worker threads
        for (int j = 0; j < numThreads; j++) {
            threads.add(new LamportGenThread()); //Initial setup, sanity check, and to make the normal thread removal loop not require a conditional.
        }
Severity: Minor
Found in src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.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 generateMerkleTreeFromScratchFile has 67 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public String generateMerkleTreeFromScratchFile(String scratchFileName, int numLayers) {
        try {
            String tempDir = new Random().nextInt(10000000) + ""; //Name of temporary directory to hold progress files. Not deleted on failure for manual recovery purposes.
            File tempDirFile = new File(tempDir);
            tempDirFile.mkdir();
Severity: Major
Found in src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java - About 2 hrs to fix

    Method generateScratchFile has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public boolean generateScratchFile(String scratchFileName, String privateKey, int numLayers, int numThreads, int keysPerThread) {
            ArrayList<LamportGenThread> threads = new ArrayList<>(); //ArrayList to hold worker threads
            for (int j = 0; j < numThreads; j++) {
                threads.add(new LamportGenThread()); //Initial setup, sanity check, and to make the normal thread removal loop not require a conditional.
            }
    Severity: Major
    Found in src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java - About 2 hrs to fix

      File MerkleTreeGenLimitless.java has 259 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      package io.codepace.cozy.address;
      
      import java.io.File;
      import java.io.PrintWriter;
      import java.nio.file.Files;
      Severity: Minor
      Found in src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java - About 2 hrs to fix

        Method generateMerkleTreeFromScratchFile has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public String generateMerkleTreeFromScratchFile(String scratchFileName, int numLayers) {
                try {
                    String tempDir = new Random().nextInt(10000000) + ""; //Name of temporary directory to hold progress files. Not deleted on failure for manual recovery purposes.
                    File tempDirFile = new File(tempDir);
                    tempDirFile.mkdir();
        Severity: Minor
        Found in src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java - About 2 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 main has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static void main(String[] args) //A messy test method, in here for convenience. Will be removed before final release.
            {
                //launch();
                Scanner scan = new Scanner(System.in);
                System.out.println("Generate address (1) normally or (2) from scratch file or (3) just generate scratch file?");
        Severity: Minor
        Found in src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java - About 1 hr to fix

          Method generateScratchFile has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public boolean generateScratchFile(String scratchFileName, String privateKey, int numLayers, int numThreads, int keysPerThread) {
          Severity: Minor
          Found in src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java - About 35 mins to fix

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

                @SuppressWarnings("unused")
                private String getLamportPrivateKey() {
                    int len = CS.length();
                    return "" + CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) +
                            CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) + CS.charAt(lmpPrivGen.nextInt(len)) +
            src/main/java/io/codepace/cozy/address/LamportGenThread.java on lines 143..150

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

            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 //Checks for addresses folder, if it doesn't exist, it creates. If it fails (likely due to write permission issues), the application exits.
                    {
                        File addressFolder = new File("addresses");
                        if (!addressFolder.exists()) {
                            addressFolder.mkdir();
            src/main/java/io/codepace/cozy/MerkleAddressUtility.java on lines 48..60

            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

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

                private String SHA256ReturnBase32(String toHash) {
                    try {
                        return base32.encodeAsString(md.digest(toHash.getBytes("UTF-8"))).substring(0, 32);
                    } catch (Exception e) {
                        e.printStackTrace();
            src/main/java/io/codepace/cozy/MerkleAddressUtility.java on lines 493..503
            src/main/java/io/codepace/cozy/MerkleAddressUtility.java on lines 554..564
            src/main/java/io/codepace/cozy/address/LamportGenThread.java on lines 159..169
            src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java on lines 304..313

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

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

                @SuppressWarnings("unused")
                private String SHA256Short(String toHash) //Each hash is shortened to 16 characters based on a 64-character charset. 64^16=79,228,162,514,264,337,593,543,950,336 (Aka more than enough for Lamport)
                {
                    try {
                        return base64.encodeAsString(md.digest(toHash.getBytes("UTF-8"))).substring(0, 16);
            src/main/java/io/codepace/cozy/MerkleAddressUtility.java on lines 493..503
            src/main/java/io/codepace/cozy/MerkleAddressUtility.java on lines 554..564
            src/main/java/io/codepace/cozy/address/LamportGenThread.java on lines 159..169
            src/main/java/io/codepace/cozy/address/MerkleTreeGenLimitless.java on lines 338..345

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

            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

            There are no issues that match your filters.

            Category
            Status