I have seen buffer overflows
in other programming languages, but how does it look in Java?
Asked
Active
Viewed 522 times
-1

AndreasJan
- 7
- 3
-
1Buffer overflows in the sense of C and C++ do not happen. Any attempt to write beyond the end of a Java array results in an immediate exception. (But if you do something daft and implement your buffers and buffer writing in native code, all bets are off.) – Stephen C Aug 05 '20 at 04:56
-
Thank you, sir. Stephan C.., for the full explanation, could you send me an example? :) – AndreasJan Aug 05 '20 at 05:00
-
Read the duplink. You should be able to write an example yourself. Write a Java program that creates an array and attempts to write outside of its bounds. Run it, and see what happens. (I assume that you are asking this question because you want to learn. Learn by doing!) – Stephen C Aug 05 '20 at 05:02
1 Answers
0
Does Java have buffer overflows?
The above answer explains why it is not common in java to actually trigger a buffer overflow. If you get one, the error is usually not in your code, unless you program with a native interface.
I guess (speculation here) that it then depends on the native interface what a possible exception might look like, or wether the exception is handled at all, or the JVM will just crash with a system level exception.

TreffnonX
- 2,924
- 15
- 23