Menu

#1159 false positive UnusedFormalParameter readObject(ObjectInputStream) if not used

PMD-5.1.0
closed
None
PMD
3-Major
Bug
2014-02-01
2013-12-24
Dan Katzel
No

I have recently started to use the SerialziationProxy Pattern described in Effective Java 2nd ed to handle custom serialization of objects.

This pattern does not allow the JVM to use the Serialization readObject(ObjectInputStream) method for security reasons and so requires the implementing class to implement the method like this:

private void readObject(ObjectInputStream stream) throws InvalidObjectException{
   throw new InvalidObjectException("Proxy required");
}

Since the method signature can not be changed for Serialization to work, I have to keep the stream parameter even though I don't use it. The Serialization contract requires that this method be private.

Classes I write using this technique get flagged by PMD for UnusedFormalParameter : "Avoid unused method parameters such as 'stream'."

Perhaps there should be an exception in the rules for the private methods required for serialization so they are treated more like methods from an interface.

Thank you

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-02-01
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.1.0
     
  • Andreas Dangel

    Andreas Dangel - 2014-02-01
     

Log in to post a comment.