Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6367855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:36:08+00:00 2026-05-25T00:36:08+00:00

I have a very creative solution to allow my unsigned code all access through

  • 0

I have a very creative solution to allow my unsigned code all access through my signed library. Although bad practice, I fear I have no other solution (except rewriting a lot of code, that then needs to be rewrited back).

I have the following class:

public abstract class full {
    public static <T,S,P> S access(final T object, final String function, final P parameter) {
        AccessController.doPrivileged(new PrivilegedAction<S>() {
            @Override
            public S run() {
                try {
                    if (parameter == null) {
                        Class[] argTypes = { };
                        Object passedArgv[] = { };
                        return (S)object.getClass().getMethod(function, argTypes).invoke(object, passedArgv);
                    } else {
                        Class[] argTypes = { parameter.getClass() };
                        Object passedArgv[] = { parameter };
                        return (S)object.getClass().getMethod(function, argTypes).invoke(object, passedArgv);
                    }
                } catch (NoSuchMethodException ex) {
                    Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SecurityException ex) {
                    Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
                } catch (InvocationTargetException ex) {
                    Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
                }
                return null;
            }
        });
        return null;
    }
}

It works great for functions that return Objects, but not for primitives.
Boolean bool = full.access(..);
will result in a nullpointer, because generic methods can’t handle primitives.

Any ideas about how to take the right approach?

To test:

public static Boolean test() {
    return true;
}

public Main() {
    System.out.println(((Boolean)redirect.full.access(this, "test", null)));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:36:09+00:00Added an answer on May 25, 2026 at 12:36 am

    The reason you are getting a NullPointerException is because you are always returning null. You call doPrivileged(...), yet null is still returned. Try returning the output of doPrivileged(...). By the looks of things, Auto(un)boxing is working here on both the inputs and the returned outputs.

    This worked for me (I passed in a primitive int, and expected a primitive boolean):

    public class ATest
    {
        public static void main(String[] args) throws UnsupportedEncodingException
        {
            int i = 5;
            Object equals = new Object();
    
            boolean b = full.access(i, "equals", equals);
    
            System.out.println(b);
        }
    
        public static class full
        {
            public static <T, S, P> S access(final T object, final String function, final P parameter)
            {
                return AccessController.doPrivileged(new PrivilegedAction<S>()
                {
                    @Override
                    public S run()
                    {
                        try
                        {
                            if (parameter == null)
                            {
                                Class[] argTypes = {};
                                Object passedArgv[] = {};
                                return (S) object.getClass().getMethod(function, argTypes)
                                        .invoke(object, passedArgv);
                            }
                            else
                            {
                                Class[] argTypes = { parameter.getClass() };
                                Object passedArgv[] = { parameter };
                                return (S) object.getClass().getMethod(function, argTypes)
                                        .invoke(object, passedArgv);
                            }
                        }
                        catch (NoSuchMethodException ex)
                        {
                            Logger.getLogger(full.class.getName()).log(Level.ALL, null, ex);
                        }
                        catch (SecurityException ex)
                        {
                            Logger.getLogger(full.class.getName()).log(Level.ALL, null, ex);
                        }
                        catch (IllegalAccessException ex)
                        {
                            Logger.getLogger(full.class.getName()).log(Level.ALL, null, ex);
                        }
                        catch (InvocationTargetException ex)
                        {
                            Logger.getLogger(full.class.getName()).log(Level.ALL, null, ex);
                        }
                        return null;
                    }
                });
            }
        }
    }
    

    On another note, you could make this more robust. When I passed in an Integer instead of an Object, the equals method was not found, even though it would have been a valid method call. If you do not find the method with the given Class, you should check again with the classes’ parent classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very bad code written in php. It consumes a lot memory, and
I have a very simple problem which requires a very quick and simple solution
I have a very large code base that contains extensive unit tests (using CppUnit).
I have very little SAP ERP knowledge. I wrote some code to create a
I have very big unsigned integral number in NSString. This may be big to
I have very simple aspx page & code: <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default
I have very big solution, and it compiling every time I'm tring to debug.
We have very strange problem, one of our applications is continually querying server by
I have very little experience building software for Windows, and zero experience using the
i have very simple problem. I need to create model, that represent element of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.