Skip to content

chore: add run_infer.yml #5456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2024

Conversation

vil02
Copy link
Member

@vil02 vil02 commented Sep 20, 2024

This PR configures infer. When looking on the current ignore list in .inferconfig, I must stay that the majority of the warnings look reasonable and having this tool in our CI might enforce better codding standards (cf. #5454). Please have a look below, for the hidden text - it contians all of the warnings without ignoring any of the files.

Currently marked as a draft, because the Build infer step takes too long. I need to build it from the source, because the versions 1.2.0 and 1.1.0 do not work with this project. Infer build is cached. The key of the used to caching used the number of the week, so infer has to be rebuild every week (updates in the infer repository happen quite often). I hope they will release soon, so the build from source will not be longer needed.

Similar to:

Infer log without ignoring any files
#0
src/main/java/com/thealgorithms/ciphers/a5/CompositeLFSR.java:34: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 34) is dereferenced. 
  32.           bitCount.put(Boolean.TRUE, 0);
  33.   
  34. >         registers.forEach(lfsr -> bitCount.put(lfsr.getClockBit(), bitCount.get(lfsr.getClockBit()) + 1));
  35.           return bitCount.get(Boolean.FALSE) <= bitCount.get(Boolean.TRUE);
  36.       }

#1
src/main/java/com/thealgorithms/conversions/RomanToInteger.java:45: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 45) is dereferenced. 
  43.               }
  44.   
  45. >             int currentNum = ROMAN_TO_INT.get(c);
  46.   
  47.               // if current number greater than prev max previous then add

#2
src/main/java/com/thealgorithms/conversions/UnitsConverter.java:80: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 80) is dereferenced. 
  78.           }
  79.           final var conversionKey = Pair.of(inputUnit, outputUnit);
  80. >         return conversions.get(conversionKey).convert(value);
  81.       }
  82.   

#3
src/main/java/com/thealgorithms/datastructures/crdt/GCounter.java:43: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 43) is dereferenced. 
  41.        */
  42.       public void increment() {
  43. >         counterMap.put(myId, counterMap.get(myId) + 1);
  44.       }
  45.   

#4
src/main/java/com/thealgorithms/datastructures/crdt/GCounter.java:67: error: Null Dereference(NULLPTR_DEREFERENCE)
  `i` could be null (null value originating from line 67) and is dereferenced. 
  65.       public boolean compare(GCounter other) {
  66.           for (int i = 0; i < n; i++) {
  67. >             if (this.counterMap.get(i) > other.counterMap.get(i)) {
  68.                   return false;
  69.               }

#5
src/main/java/com/thealgorithms/datastructures/crdt/GCounter.java:81: error: Null Dereference(NULLPTR_DEREFERENCE)
  `i` could be null (null value originating from line 81) and is dereferenced. 
  79.       public void merge(GCounter other) {
  80.           for (int i = 0; i < n; i++) {
  81. >             this.counterMap.put(i, Math.max(this.counterMap.get(i), other.counterMap.get(i)));
  82.           }
  83.       }

#6
src/main/java/com/thealgorithms/datastructures/crdt/PNCounter.java:47: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 47) is dereferenced. 
  45.        */
  46.       public void increment() {
  47. >         pCounter.put(myId, pCounter.get(myId) + 1);
  48.       }
  49.   

#7
src/main/java/com/thealgorithms/datastructures/crdt/PNCounter.java:54: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 54) is dereferenced. 
  52.        */
  53.       public void decrement() {
  54. >         nCounter.put(myId, nCounter.get(myId) + 1);
  55.       }
  56.   

#8
src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java:30: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 30) is dereferenced. 
  28.       void addEdge(E from, E to) {
  29.           try {
  30. >             adj.get(from).add(to);
  31.           } catch (Exception E) {
  32.               adj.put(from, new ArrayList<E>());

#9
src/main/java/com/thealgorithms/datastructures/graphs/KahnsAlgorithm.java:74: error: Null Dereference(NULLPTR_DEREFERENCE)
  `ArrayList AdjacencyList.getAdjacents(Comparable)` could be null (from the call to `AdjacencyList.getAdjacents(...)` on line 74) and is dereferenced. 
  72.                   inDegree.put(vertex, 0);
  73.               }
  74. >             for (E adjacent : graph.getAdjacents(vertex)) {
  75.                   try {
  76.                       inDegree.put(adjacent, inDegree.get(adjacent) + 1);

#10
src/main/java/com/thealgorithms/datastructures/heaps/GenericHeap.java:80: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 80) is dereferenced. 
  78.   
  79.       public void updatePriority(T item) {
  80. >         int index = map.get(item);
  81.           // because we enter lesser value then old vale
  82.           upHeapify(index);

#11
src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java:146: error: Null Dereference(NULLPTR_DEREFERENCE)
  `linkOperations->head->next` could be null (from the call to `DoublyLinkedList()` on line 130) and is dereferenced in the call to `LinkOperations.delete(...)`. 
  144.           myList.displayBackwards();
  145.   
  146. >         linkOperations.delete(7);
  147.           myList.display(); // <-- 10(head) <--> 13(tail) -->
  148.           myList.displayBackwards();

#12
src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java:146: error: Null Dereference(NULLPTR_DEREFERENCE)
  `linkOperations->head` could be null (from the call to `LinkOperations.deleteTail()` on line 142) and is dereferenced in the call to `LinkOperations.delete(...)`. 
  144.           myList.displayBackwards();
  145.   
  146. >         linkOperations.delete(7);
  147.           myList.display(); // <-- 10(head) <--> 13(tail) -->
  148.           myList.displayBackwards();

#13
src/main/java/com/thealgorithms/datastructures/trees/CreateBinaryTreeFromInorderPreorder.java:64: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 64) is dereferenced. 
  62.   
  63.           Node root = new Node(preorder[preStart]);
  64. >         int i = inorderMap.get(preorder[preStart]);
  65.           int leftNodesCount = i - inStart;
  66.           int rightNodesCount = size - leftNodesCount - 1;

#14
src/main/java/com/thealgorithms/divideandconquer/ClosestPair.java:338: error: Null Dereference(NULLPTR_DEREFERENCE)
  `cp->point1` could be null (from the call to `ClosestPair(...)` on line 310) and is dereferenced. 
  336.           // minimum distance coordinates and distance output
  337.           System.out.println("Output Data");
  338. >         System.out.println("(" + cp.point1.x + ", " + cp.point1.y + ")");
  339.           System.out.println("(" + cp.point2.x + ", " + cp.point2.y + ")");
  340.           System.out.println("Minimum Distance : " + result);

#15
src/main/java/com/thealgorithms/dynamicprogramming/Fibonacci.java:69: error: Null Dereference(NULLPTR_DEREFERENCE)
  `i` could be null (null value originating from line 69) and is dereferenced. 
  67.           }
  68.   
  69. >         return fib.get(n);
  70.       }
  71.   

#16
src/main/java/com/thealgorithms/maths/NthUglyNumber.java:70: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 70) is dereferenced. 
  68.   
  69.       private long computeCandidate(final int candidateBase) {
  70. >         return candidateBase * uglyNumbers.get(positions.get(candidateBase));
  71.       }
  72.   

#17
src/main/java/com/thealgorithms/maths/SimpsonIntegration.java:64: error: Null Dereference(NULLPTR_DEREFERENCE)
  `i` could be null (null value originating from line 64) and is dereferenced. 
  62.           for (int i = 0; i < data.size(); i++) {
  63.               if (i == 0 || i == data.size() - 1) {
  64. >                 integralEvaluation += data.get(i);
  65.                   System.out.println("Multiply f(x" + i + ") by 1");
  66.               } else if (i % 2 != 0) {

#18
src/main/java/com/thealgorithms/others/Dijkstra.java:170: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 170) is dereferenced. 
  168.           // another pass to set neighbouring vertices
  169.           for (Edge e : edges) {
  170. >             graph.get(e.v1).neighbours.put(graph.get(e.v2), e.dist);
  171.               // graph.get(e.v2).neighbours.put(graph.get(e.v1), e.dist); // also do this for an
  172.               // undirected graph

#19
src/main/java/com/thealgorithms/sorts/TopologicalSort.java:119: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 119) is dereferenced. 
  117.       private static String sort(Graph graph, Vertex u, LinkedList<String> list) {
  118.           u.color = Color.GRAY;
  119. >         graph.adj.get(u.label).next.forEach(label -> {
  120.               if (graph.adj.get(label).color == Color.WHITE) {
  121.                   list.addFirst(sort(graph, graph.adj.get(label), list));

#20
src/main/java/com/thealgorithms/sorts/TopologicalSort.java:120: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 120) is dereferenced. 
  118.           u.color = Color.GRAY;
  119.           graph.adj.get(u.label).next.forEach(label -> {
  120. >             if (graph.adj.get(label).color == Color.WHITE) {
  121.                   list.addFirst(sort(graph, graph.adj.get(label), list));
  122.               } else if (graph.adj.get(label).color == Color.GRAY) {

#21
src/main/java/com/thealgorithms/strings/AhoCorasick.java:110: error: Null Dereference(NULLPTR_DEREFERENCE)
  `childNode` could be null (null value originating from line 108) and is dereferenced. 
  108.                   Node childNode = root.getChild().get(rc);
  109.                   q.add(childNode); // Add child node to the queue
  110. >                 childNode.setSuffixLink(root); // Set suffix link to the root
  111.               }
  112.           }

#22
src/test/java/com/thealgorithms/datastructures/caches/LRUCacheTest.java:42: error: Null Dereference(NULLPTR_DEREFERENCE)
  `(*mruCache->data)->__infer_model_backing_collection_empty` could be null (from the call to `LRUCache.put(...)` on line 41) and is dereferenced in the call to `LRUCache.put(...)`. 
  40.           LRUCache<Integer, Integer> mruCache = new LRUCache<>(SIZE);
  41.           mruCache.put(null, 2);
  42. >         mruCache.put(6, null);
  43.   
  44.           assertEquals(2, mruCache.get(null));

#23
src/test/java/com/thealgorithms/datastructures/lists/SkipListTest.java:65: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (from the call to `SkipListTest.createSkipList()` on line 60) is dereferenced in the call to `SkipList.remove(...)`. 
  63.           print(skipList);
  64.   
  65. >         skipList.remove(mostRightValue);
  66.   
  67.           print(skipList);

#24
src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java:25: error: Null Dereference(NULLPTR_DEREFERENCE)
  `kdTree->root` could be null (from the call to `KDTree(...)` on line 23) and is dereferenced in the call to `KDTree.findMin(...)`. 
  23.           KDTree kdTree = new KDTree(coordinates);
  24.   
  25. >         assertEquals(5, kdTree.findMin(0).getCoordinate(0));
  26.           assertEquals(12, kdTree.findMin(1).getCoordinate(1));
  27.       }

#25
src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java:42: error: Null Dereference(NULLPTR_DEREFERENCE)
  `KDTree$Node KDTree.getRoot()` could be null (from the call to `KDTree(...)` on line 39) and is dereferenced. 
  40.   
  41.           kdTree.delete(pointOf(30, 40));
  42. >         assertEquals(35, kdTree.getRoot().getPoint().getCoordinate(0));
  43.           assertEquals(45, kdTree.getRoot().getPoint().getCoordinate(1));
  44.       }

#26
src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java:58: error: Null Dereference(NULLPTR_DEREFERENCE)
  `kdTree->root` could be null (from the call to `KDTree(...)` on line 56) and is dereferenced in the call to `KDTree.findNearest(...)`. 
  56.           KDTree kdTree = new KDTree(coordinates);
  57.   
  58. >         assertEquals(pointOf(7, 2), kdTree.findNearest(pointOf(7, 2)));
  59.           assertEquals(pointOf(8, 1), kdTree.findNearest(pointOf(8, 1)));
  60.           assertEquals(pointOf(2, 3), kdTree.findNearest(pointOf(1, 1)));

#27
src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java:59: error: Null Dereference(NULLPTR_DEREFERENCE)
  `kdTree->root` could be null (from the call to `KDTree(...)` on line 56) and is dereferenced in the call to `KDTree.findNearest(...)`. 
  57.   
  58.           assertEquals(pointOf(7, 2), kdTree.findNearest(pointOf(7, 2)));
  59. >         assertEquals(pointOf(8, 1), kdTree.findNearest(pointOf(8, 1)));
  60.           assertEquals(pointOf(2, 3), kdTree.findNearest(pointOf(1, 1)));
  61.           assertEquals(pointOf(5, 4), kdTree.findNearest(pointOf(5, 5)));

#28
src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java:60: error: Null Dereference(NULLPTR_DEREFERENCE)
  `kdTree->root` could be null (from the call to `KDTree(...)` on line 56) and is dereferenced in the call to `KDTree.findNearest(...)`. 
  58.           assertEquals(pointOf(7, 2), kdTree.findNearest(pointOf(7, 2)));
  59.           assertEquals(pointOf(8, 1), kdTree.findNearest(pointOf(8, 1)));
  60. >         assertEquals(pointOf(2, 3), kdTree.findNearest(pointOf(1, 1)));
  61.           assertEquals(pointOf(5, 4), kdTree.findNearest(pointOf(5, 5)));
  62.       }

#29
src/test/java/com/thealgorithms/datastructures/trees/KDTreeTest.java:61: error: Null Dereference(NULLPTR_DEREFERENCE)
  `kdTree->root` could be null (from the call to `KDTree(...)` on line 56) and is dereferenced in the call to `KDTree.findNearest(...)`. 
  59.           assertEquals(pointOf(8, 1), kdTree.findNearest(pointOf(8, 1)));
  60.           assertEquals(pointOf(2, 3), kdTree.findNearest(pointOf(1, 1)));
  61. >         assertEquals(pointOf(5, 4), kdTree.findNearest(pointOf(5, 5)));
  62.       }
  63.   }

#30
src/test/java/com/thealgorithms/datastructures/trees/LazySegmentTreeTest.java:14: error: Null Dereference(NULLPTR_DEREFERENCE)
  `LazySegmentTree$Node LazySegmentTree$Node.getLeft()` could be null (from the call to `LazySegmentTree(...)` on line 12) and is dereferenced. 
  12.           LazySegmentTree lazySegmentTree = new LazySegmentTree(arr);
  13.           assertEquals(55, lazySegmentTree.getRoot().getValue());
  14. >         assertEquals(15, lazySegmentTree.getRoot().getLeft().getValue());
  15.           assertEquals(40, lazySegmentTree.getRoot().getRight().getValue());
  16.       }

#31
src/test/java/com/thealgorithms/searches/QuickSelectTest.java:188: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 188) is dereferenced in the call to `QuickSelect.select(...)`. 
  186.       @Test
  187.       void quickSelectNullList() {
  188. >         NullPointerException exception = assertThrows(NullPointerException.class, () -> QuickSelect.select(null, 0));
  189.           String expectedMsg = "The list of elements must not be null.";
  190.           assertEquals(expectedMsg, exception.getMessage());

#32
src/test/java/com/thealgorithms/stacks/PostfixToInfixTest.java:31: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 31) is dereferenced in the call to `PostfixToInfix.getPostfixToInfix(...)`. 
  29.       @Test
  30.       void testNullPostfixExpression() {
  31. >         assertThrows(NullPointerException.class, () -> PostfixToInfix.getPostfixToInfix(null));
  32.       }
  33.   }

#33
src/test/java/com/thealgorithms/strings/HorspoolSearchTest.java:80: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 80) is dereferenced in the call to `HorspoolSearch.findFirst(...)`. 
  78.       @Test
  79.       void testFindFirstPatternNull() {
  80. >         assertThrows(NullPointerException.class, () -> HorspoolSearch.findFirst(null, "Hello World"));
  81.       }
  82.   

#34
src/test/java/com/thealgorithms/strings/HorspoolSearchTest.java:85: error: Null Dereference(NULLPTR_DEREFERENCE)
  null (null value originating from line 85) is dereferenced in the call to `HorspoolSearch.findFirst(...)`. 
  83.       @Test
  84.       void testFindFirstTextNull() {
  85. >         assertThrows(NullPointerException.class, () -> HorspoolSearch.findFirst("Hello", null));
  86.       }
  87.   }

Found 35 issues
             Issue Type(ISSUED_TYPE_ID): #
  Null Dereference(NULLPTR_DEREFERENCE): 35

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.19%. Comparing base (63fa042) to head (5cfbda6).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #5456   +/-   ##
=========================================
  Coverage     52.19%   52.19%           
- Complexity     3244     3245    +1     
=========================================
  Files           524      524           
  Lines         15158    15158           
  Branches       2881     2881           
=========================================
  Hits           7911     7911           
  Misses         6923     6923           
  Partials        324      324           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vil02 vil02 force-pushed the configure_infer branch 14 times, most recently from aadb8f6 to 40fbbf3 Compare September 21, 2024 11:45
@vil02 vil02 marked this pull request as ready for review September 21, 2024 14:22
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, could you just rename the check to be similar in style to other checks?
image

Copy link
Member

@BamaCharanChhandogi BamaCharanChhandogi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants