Question

I'm using PODAM to populate my objects with some test data within some JUnit test cases. I've come across an error that doesn't make sense to me.

PODAM reports this line of logging when manufacturing my objects:

The setter: setId is not accessible.Setting it to accessible. However this is a security hack and your code should really adhere to Javabean standards.

I get this warning for every single one of my setters while it's trying to populate an object. In this case setId() consists of the following:

public void setId( int id )
{
    this.id = id;
}

Does anyone know why this error is getting flagged, as the method is public why is it getting flagged "not accessible".

I have looked at the PODAM source and it is checking if the method is accessible and every time it returns false, then PODAM will set the method to be accessible before invoking it:

if (!setter.isAccessible()) {
                    LOG.warn("The setter: {} is not accessible.Setting it to accessible. "
                            + "However this is a security hack and your code should really adhere to Javabean standards.",
                            setter.getName());
                    setter.setAccessible(true);
                }
                setter.invoke(retValue, setterArg);    

PODAM is actually working great and populating all the fields with random data as I wanted. I am just curious as to why I am getting this error each time and if there is an issue within the code casuing it to not adhear to the standards.

Was it helpful?

Solution

isAccessible() returning false for public setters

Yes. It should do. According to the javadocs, the accessible flag determines whether the Method object ignores the normal Java access rules when you attempt to invoke the method (reflectively) via the Method object. According to the javadoc, the flag defaults to false ... meaning "apply the Java access rules".

However. the code snippet you posted seems to be misinterpreting the accessible flag as indicating that the method can be invoked. That is incorrect ... and the end result is spurious warnings.

This looks like a bug in PODAM, and I recommend that you raise an issue with the maintainers of the PODAM library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top