While a strict reading of the JLS would imply that all three should be in the pool, in reality only one is. Which is fine because nothing in the program has any need at all for the substrings "tex" and "t" by themselves. The whole thing is resolved at compile time as a single string "text", and that's what gets stored. You can see this with a test program and the javap tool.
Note that both foo and barbaz appear in the constant table, but not bar or baz individually.
Incidentally, the reason I changed
is because I wanted the variable name to be different from the content, so that we could see that both were included. If you change this to be a local variable within a method, then the name foo will not be included in the constant table. I'll leave that as an excercise for anyone who wants to try it.