#FindBugs vulnerable to finalizer attack

1 messages ยท Page 1 of 1 (latest)

fading walrus
#

Constructor throws exceptions, leaving object vulnerable to finalizer attacks

i have taking measures to combat this but im still gettin error therefor whenever i try to use gradle for building it im getting the error

sand pilotBOT
#

<@&987246883653156906> please have a look, thanks.

solar wren
#

declare your classes final ๐Ÿ™‚

#

You should do that anyway

fading walrus
#

all of them?

solar wren
#

yeah

fading walrus
#

ok thx

solar wren
#

As long as you can at least

#

Sometimes with inheritance you can't

fading walrus
#

yes im using inheritance

#

subclasses are inherting methods from parent class, should i prociede with finalizing my classes still @solar wren

solar wren
#

Well, not the ones being inherited but at least all the other ones

sleek sedge
flint breach
#

I think they mean making them final and not using finalize method

fading walrus
flint breach
#

do you really override the Object#finalize method?

solar wren
#

no that's findbugs

#

findbugs is noticing an issue that might crop up with certain finalize methods and reflection if you're not consistent and make things final when they should be

fading walrus
#

I meant to say i added finalize method like this: protect final void finalize with an empty body

#

It worked

flint breach
#

well but why using finalize in the first place?

#

you shouldnt

#

its deprecated

fading walrus
#

Cause of findbugs

solar wren
#

don't use finalize

#

remove it

#

Make findbugs behave, or look up what the issue is and how you can fix it

#

Probably need some decent object design and it won't happen

#

Like it said, initialize all fields in the constructor for example

sleek sedge
#

You should have a warning appearing
There is no way you would listen to findbugs but ignore basic warnings

safe badger
#

Finalize has been deprecated since java 9, and is up for removal. So you should indeed get a warning, and you really shouldn't be using it.