congo-cc / congo-parser-generator

The CongoCC Parser Generator, the Next Generation of JavaCC 21, which in turn was the next generation of JavaCC
https://discuss.congocc.org/
Other
36 stars 11 forks source link

preprocessorSymbols Map could be null or Immutable/Unmodifyable `Map.of()` #28

Closed stbischof closed 7 months ago

stbischof commented 1 year ago

https://github.com/congo-cc/congo-parser-generator/blob/a0afa3197f7af83267073fa8792806aba967b841/src/java/org/congocc/core/Grammar.java#L59

revusky commented 1 year ago

Well, the preprocessorSymbols cannot actually be null in that spot. The map is instantiated here, passed into the mainProgram method here and passed into the Grammar constructor here. And that is the only path of execution to get there, since that is the only place where that constructor is invoked.

So it can't be null and it can't be immutable either. But, to tell the truth, I don't really understand why this is much of an issue. If, by some chance, the map was null or immutable (though it can't be, as you can see from eyeballing the code) the JVM would throw an NPE and we'd have a stack trace and it would be fixed in about a minute. Or, in other words, a bug of that nature cannot really survive, has such a low life expectancy that...

stbischof commented 1 year ago

I had this null in the maven Plugin. In your Code it is fine.

But lwhen others use the classe direkt they may bit know what happens.

stbischof commented 1 year ago

Thx,

if others put a ImmutableMap in, it will also fail if you call put.

vsajip commented 7 months ago

Perhaps we just make a copy of the value passed in, which will just be an ordinary HashMap (and thus mutable).