JDK-4894447 : (reflect) Need To Access Parameter Objects in java.lang.Method
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 1.4.2
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2003-07-22
  • Updated: 2013-01-04
  • Resolved: 2012-12-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description

Name: jl125535			Date: 07/22/2003


A DESCRIPTION OF THE REQUEST :
Currently I can get the parameter Classes for a Method via Method.getParameterTypes().  What I can't get is the Objects for those parameters (which can then be introspected).

I can get field values from java.lang.reflect.Field.get() but there is no
way (that I know of) to do the same thing for parameter values of a
Method.


JUSTIFICATION :
Adding this capability will allow for much more useful logging.
I could pass an object instance that caused an exception to a logger
and it could introspect all the data members of the object _and_
all the parameters passed into the method that caused the exception.
This would allow me a better-than-average chance of recreating the
exception off-line.

This would be suitable to production environments where running with
method-callbacks or debugging turned on is inappropriate.

Clearly this information just exist in the JVM (or programs wouldn't
run!) but isn't currently exposed in an API.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would be very excited to see functionality added to java.lang.reflect.Method
that mirrored what's already available in Field:

public Object[] getParameters( Object obj )
    throws IllegalArgumentException, IllegalAccessException;

Pass in the "current" or "active" object, just like in Field.get().
Each object returned represents a parameter object, which can then be
introspected for "painless" detailed logging.
(Incident Review ID: 182223) 
======================================================================

Comments
Closing as duplicate of JDK-8004729.
08-12-2012

Having a java.lang.reflect.Parameter class to model parameters from methods and constructors, present parameter modifier information (including whether or not the parameter is synthetic), and return annotations would be a fine addition to the platform. In particular, this feature would be useful for repeating annotations if the Parameter class implemented the AnnotatedElement interface. Structured information about parameters would also allow better presentation of some information about method.
26-10-2012