static-analysis

How to find unclosed I/O resources in Java?

北城以北 提交于 2019-12-03 15:39:19
问题 Many I/O resources in Java such as InputStream and OutputStream need to be closed when they are finished with, as discussed here. How can I search my project for places where such resources are not being closed, e.g. this kind of error: private void readFile(File file) throws IOException { InputStream in = new FileInputStream(file); int nextByte = in.read(); while (nextByte != -1) { // Do something with the byte here // ... // Read the next byte nextByte = in.read(); } // Oops! Not closing

Is it possible to decouple the code indexing capabilities of Eclipse?

岁酱吖の 提交于 2019-12-03 15:24:42
I am looking to write a static analyser for a university class. To provide more power for the tool I would like to be able to look up the call hierarchy (as Ctrl+Alt+H does in Eclipse). This would also have to be a fast operation, so the lookup would probably have to be done against an index rather than bytecode scanning. However, writing an Eclipse plugin would be too ambitious I expect. Instead I would rather decouple the parts of Eclipse which create the code index, and use a library to do lookups. The interface to the user would be on the command line, to simplify implementation. I read

Static analysis tool to check locking before access to variable

只谈情不闲聊 提交于 2019-12-03 14:38:38
I know there are a quite a few static analysis tools for C# or .Net around. See this question for a good list of available tools. I have used some of those in the past and they have a good way of detecting problems. I am currently looking for a way to automatically enforce some locking rules we have in our teams. For example I would like to enforce the following rules: "Every public method that uses member foo must acquire a lock on bar " Or "Every call to foobar event must be outside lock to bar " Writing custom FxCop rules, if feasible , seems rather complex. Is there any simpler way of

Java Minimize Dependencies

二次信任 提交于 2019-12-03 13:46:24
问题 I have a situation where there is a small piece of Java code that has a large number of jars that it depends on. However, the dependencies inside these jars are very shallow. In most cases it only depends on a jar for a single interface. Instead of distributing all of the jars with the application, I would like to just distribute the specific class files inside the jars that it actually uses. The reason for this is to conserve space (this code will live in an applet). Does anyone know of a

How can I run GCC/Clang for static analysis? (warnings only)

别来无恙 提交于 2019-12-03 12:30:14
问题 Without compiling code, I would like GCC or Clang to report warnings. Is it possible to run the compiler for static analysis only? I can't find a way to pass the compiler warning flags and tell it not to compile. edit: just found that clang has a static analyser 回答1: Both GCC and Clang have an option -fsyntax-only that makes the compiler only perform syntax checking without any actual compilation. 回答2: In addition to the other replies, gcc is doing some analysis during compilation (and even

Code Contracts: Why are some invariants not considered outside the class?

天大地大妈咪最大 提交于 2019-12-03 11:14:05
Consider this immutable type: public class Settings { public string Path { get; private set; } [ContractInvariantMethod] private void ObjectInvariants() { Contract.Invariant(Path != null); } public Settings(string path) { Contract.Requires(path != null); Path = path; } } Two things to notice here: There is a contract invariant which ensures the Path property can never be null The constructor checks the path argument value to respect the previous contract invariant At this point, a Setting instance can never have a null Path property. Now, look at this type: public class Program { private

dredge function error - R package MuMln

不羁岁月 提交于 2019-12-03 10:02:26
I have to do statistical analyses on a data set. I would like to create all the possible models and to test them with the dredge function but it doesn't work. Indeed, when I type: glm1<-glm(presabs~dca1+dca2+se1+se2, family=binomial(logit)) dredge(glm1) I got this error: Erreur in dredge(glm1) : 'global.model''s 'na.action' argument is not set and options('na.action') is "na.omit" Can someone help me? I know this has been solved, however I came across the same issue and think there is a better way. The issue with using options(na.action = "na.fail") is that it changes the global settings of R.

Typesafe varargs in C with gcc

无人久伴 提交于 2019-12-03 09:51:30
Many times I want a function to receive a variable number of arguments, terminated by NULL, for instance #define push(stack_t stack, ...) _push(__VARARG__, NULL); func _push(stack_t stack, char *s, ...) { va_list args; va_start(args, s); while (s = va_arg(args, char*)) push_single(stack, s); } Can I instruct gcc or clang to warn if foo receives non char* variables? Something similar to __attribute__(format) , but for multiple arguments of the same pointer type. I know you're thinking of using __attribute__((sentinel)) somehow, but this is a red herring. What you want is to do something like

Explain System.Diagnostics.CodeAnalysis.SuppressMessage

旧时模样 提交于 2019-12-03 09:49:43
问题 I have this kind of code in some applications (from microsoft) [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "CounterClockwise", Scope = "member", Target = "ScePhotoViewer.PhotoDisplayControl.#RotatePhotoCounterClockwiseCommand" )] Can anyone explain me this ? Is there any blog explaining how to use it, the real benefits... Thanks Jonathan 回答1: This attribute is used by Team Foundation Server's (TFS)

Is there a tool to validate an Azure DevOps Pipeline locally?

落花浮王杯 提交于 2019-12-03 09:49:28
问题 When making changes to YAML-defined Azure DevOps Pipelines, it can be quite tedious to push changes to a branch just to see the build fail with a parsing error (valid YAML, but invalid pipeline definition) and then try to trial-and-error fix the problem. It would be nice if the feedback loop could be made shorter, by analyzing and validating the pipeline definition locally; basically a linter with knowledge about the various resources etc that can be defined in an Azure pipline. However, I