Questions tagged [heap-pollution]

Heap pollution simply implies that you have "bad stuff" in your heap. It is an analogy to water pollution which is where you have "bad stuff" in the water.

Heap pollution simply implies that you have "bad stuff" in your heap. It is an analogy to water pollution which is where you have "bad stuff" in the water.

It is not a particularly good analogy, but it is the terminology that the Java folks coined. They have defined it here:

http://docs.oracle.com/javase/tutorial/java/generics/nonReifiableVarargsType.html#heap_pollution

8 questions
19
votes
5 answers

varargs heap pollution : what's the big deal?

I was reading about varargs heap pollution and I don't really get how varargs or non-reifiable types would be responsible for problems that do not already exist without genericity. Indeed, I can very easily replace public static void…
Dici
  • 25,226
  • 7
  • 41
  • 82
16
votes
1 answer

Java 1.7 varargs function reported as unchecked warning

We use some varargs functions and as we move to java 1.7 we are getting a strange unchecked warning. Function add in interface ICache public interface ICache { void add(Object source, O... objects); } in an interface reports the…
Neil Wightman
  • 1,103
  • 2
  • 9
  • 29
15
votes
2 answers

What is an apparently correct example of Java code causing heap pollution?

I'm trying to decide what to do every time I get a Java heap pollution warning when using parameterized varargs such as in public static LinkedList list(T... elements) { ... } It seems to me that if I am confident not to be using some…
user118967
  • 4,895
  • 5
  • 33
  • 54
7
votes
2 answers

Is this a heap pollution work around?

I have a constructor like below public MyConstructor(MyObject ... objects) { // ... } Eclipse warns me with the following message: Type safety: Potential heap pollution via varargs parameter objects I change the constructor like…
Stephan
  • 41,764
  • 65
  • 238
  • 329
1
vote
1 answer

How can (-1 >= sizeof(buffer)) ever be true? Program fail to get right results of comparison

The program runs into impossible execution routine, where if( len >= sizeof(buff) ) should never be true in reality, however it happens. As is shown by the printf output len:-1__1024: len, whose value is -1, is larger than sizeof(buff), which is…
river
  • 694
  • 6
  • 22
0
votes
1 answer

Is there any scenario where heap pollution from parameterized vararg type occurs without an explicit `Object[]` conversion?

I have been looking at various answers and articles regarding heap pollution when using non-reifiable varargs parameters. All examples I have found use an Object[] conversion followed by an array element write. The heap pollution only ever seems to…
Timothy Cole
  • 304
  • 2
  • 7
0
votes
0 answers

Generic Vararg Safety

I have a function. I like my function. It makes lists and it makes me happy. My IDE gives me a warning about my function though, talking about potential heap pollution. I can add an annotation to suppress this warning, but I want to make sure I'm…
Carl Shiles
  • 434
  • 3
  • 15
0
votes
2 answers

How can Heap Pollution cause a security flaw

I came across this rule in the CERT Secure Coding Standart for Java. Heap Pollution. I understand this can cause the programm throwing an exception at runtime, but i can't understand how this could cause a security issue like dos or something. Could…
Exagon
  • 4,798
  • 6
  • 25
  • 53