Questions tagged [code-analysis]

Code Analysis is the process of analyzing the code of the application to discover, review, validate or verify certain properties of the application. This is useful during the process of development and for testing the application before it is put in production mode, especially for checking the security related aspects.

Code Analysis is the process of analyzing the code of the application to discover, review, validate or verify certain properties of the application. This is useful during the process of development and for testing the application before it is put in production mode, especially for checking the security related aspects. Code analysis can be classified from several perspectives, including:

1. What can be analyzed: source code or binary code (byte code) of the application can be analyzed. Both of these categories have their pros and cons.

2. How or When should code be analyzed: Code can be analyzed statically (without executing it) or dynamically (while the application is executed). Static analysis, being conservative, is prone to false positive, but it is exhaustive. On the other hand, dynamic analysis, being very accurate, may miss certain behaviors which are not manifested in any of the execution monitored (because dynamic analysis only analyzes code that is executed - i.e. when certain conditions are met)

3. Purpose of the analysis: Flaws can be found, like NULL pointer dereferencing or passing an ASCII string instead of a Unicode string. Furthermore, aspects of the code can be found, like building various graphs of dependencies or deducing the conditions under which recursion will occur.

1882 questions
25
votes
6 answers

CA1500 vs. SA1309 - Which one wins?

I'll prefix by saying that I understand that both Code Analysis and StyleCop are meant as guidelines, and many people chose to ignore these anyway. But having said that, I'd like to see what the general consensus is with regard to these two…
Jerad Rose
  • 15,235
  • 18
  • 82
  • 153
25
votes
4 answers

How to enable Code Analysis in Visual Studio 2010 Professional?

I can see that we can enable code analysis in Visual Studio Team Systems. But i am using Visual Studio 2010 Professional. Do we have any option to enable code analysis in this version or can we integrate any tools like FxCop and StyleCop with this…
kiran826
  • 331
  • 1
  • 4
  • 10
25
votes
4 answers

What tools and techniques do you use to find dead code?

What tools and techniques do you use to find dead code in .NET? In the past, I've decorated methods with the Obsolete attribute (passing true so the compiler will issue an error, as described in MSDN). I'd be interested in seeing the suggestions of…
Scott Lawrence
  • 6,993
  • 12
  • 46
  • 64
23
votes
3 answers

Error in FxCop Phoenix analysis engine

So I'm trying to run a bunch of rules which are defined in a RuleSet. The RuleSet file is actually generated using Sonarqube - I've selected absolutely all rules in there, including the FxCop, ReSharper and StyleCop rules. I'm kicking off FxCop like…
Trayek
  • 4,410
  • 3
  • 24
  • 39
22
votes
3 answers

Tool to help eliminate wildcard imports

I'm refactoring and eliminating wildcard imports on some fairly monolithic code. Pylint seems to do a great job of listing all the unused imports that come along with a wildcard import, but what i wish it did was provide a list of used imports so I…
Paul
  • 2,973
  • 6
  • 31
  • 40
22
votes
3 answers

PL/SQL pre-compile and Code Quality checks in an automated build environment?

We build software using Hudson and Maven. We have C#, java and last, but not least PL/SQL sources (sprocs, packages, DDL, crud) For C# and Java we do unit tests and code analysis, but we don't really know the health of our PL/SQL sources before we…
22
votes
1 answer

Detect Recursive calls in C# code

I want to find all recursive calls in my code. If I open file in Visual Studio, I get "Recursive call" icon on left side of Editor. I want to inspect whole solution for such calls. I used Resharper Command Line tools and VS's add-in Resharper -…
Dejan Dakić
  • 2,418
  • 2
  • 25
  • 39
21
votes
3 answers

Can one make Code Analysis understand Code Contracts?

When using Code Analysis and Code Contracts in combination, I get a lot of warnings like CA1062: Microsoft.Design : In externally visible method 'Foo.Bar(Log)', validate parameter 'log' before using it. In Foo.Bar, I have a contract that validates…
21
votes
3 answers

Java for each loop being flagged as UR anomaly by PMD

I would like to confirm if this is a bug on PMD? How do I file a ticket if it is. public static void main(final String[] args) { for (final String string : args) { string.getBytes(); //UR Anomaly } for (int i…
John Doe
  • 1,364
  • 1
  • 12
  • 19
21
votes
6 answers

Identifying "sensitive" code in your application

Looking to improve quality of a fairly large Python project. I am happy with the types of warnings PyLint gives me. However, they are just too numerous and hard to enforce across a large organization. Also I believe that some code is more…
Kozyarchuk
  • 21,049
  • 14
  • 40
  • 46
20
votes
3 answers

Limits of Klee (the LLVM program analysis tool)

http://klee.llvm.org/ is a program analysis tool that works by symbolic execution and constraint solving, finding possible inputs that will cause a program to crash, and outputting these as test cases. It's an extremely impressive piece of…
rwallace
  • 31,405
  • 40
  • 123
  • 242
20
votes
4 answers

How to get rid of CA2000 warning when ownership is transferred?

The following code generates two CA2000 warnings (among others, but that's not the point). public sealed class Item: IDisposable { public void Dispose() {} } public sealed class ItemContainer { public void Add(Item item) { …
Henrik
  • 23,186
  • 6
  • 42
  • 92
20
votes
4 answers

Alternative to nested type of type Expression>

I have a function used when calling a service. Before it call the service, it will create a log entry: protected TResult CallService(TService service, Expression> functionSelector) { …
Pierre-Alain Vigeant
  • 22,635
  • 8
  • 65
  • 101
20
votes
3 answers

Using Microsoft.Bcl.Async with Code Analysis causes errors

I'm trying to use Microsoft.Bcl.Async and Code Analysis, but when I run Code Analysis I get one or more errors. I'm using Visual Studio 2012 with Update 2. This is easy for me to reproduce: Create a new default Console App that targets .Net…
Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
19
votes
5 answers

Alias Analysis in Java

Can somebody point me to a framework or an implementation of alias analysis for Java. I looked at the asm framework but it only provides data flow analysis and control flow analysis. Update: Just curious but does anyone know if Findbugs does alias…
pdeva
  • 43,605
  • 46
  • 133
  • 171