Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Side-effect free methods in the Java Standard Library

I'm working on an analysis for Java programs that requires side-effect information about method calls. For standard library classes, I would like to compile a list of methods with read-only parameters. That is, methods that don't modify their arguments, or anything reachable from their arguments. I can infer a lot from the javadocs, but that will take time.

Could anyone suggest an easier reference or method for determining whether standard method calls modify their arguments? Is reading through the each javadoc entry really the best way?

Thanks!

EDIT: A bonus would be identifying methods that have no side-effects on the object either. For instance, stack.pop() would whereas stack.size() would not.

like image 453
Owen Avatar asked Jun 24 '10 19:06

Owen


People also ask

What is method side effect in Java?

A side effect is anything a method does besides computing and returning a value. Any change of instance or class field values is a side effect, as is drawing something on the screen, writing to a file or a network connection.

Does Java have side effects?

Side effects can be unavoidable: Get(x); changes the state of the input. Put(x); changes the state of the output.


1 Answers

Well, all methods taking only primitive types/strings/Object/generic types as parameters should satisfy you without further consideration. And for java.lang and java.util this should cover most of the methods.

But you'd really better to limit packages you want to process, because standard jdk offers huge library of classes for all tasks and purposes.

edit
It's somewhat fuzzier for generic types declared as E extends ModifiableObject, so see for yourself.

like image 166
Nikita Rybak Avatar answered Nov 14 '22 23:11

Nikita Rybak