This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How force code execute before native method?

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say I have a native method called "doSomething()" and there is other code written by other people that calls it, which I cannot change. Let's also assume I cannot change the native C code either, so I'm stuck with the name of the native method. How would I "wrap" the call to the native nethod "doSomething()" so that it checked for a security permission first?
Normally (if I could change the name) I'd do:

The above would break only code that uses reflection where it looks for and executes any method flagged as native, but that's a small price. HOWEVER, I cannot change the C code, so I'm unable to do the above. Also, I cannot change the code of the calling classes. What's the solution here? I'm stumped.
[ January 23, 2004: Message edited by: Robert Paris ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here's what you do. Make exactly the change you show above. Implement the Java_package_doSomething0() function in C. Have it call the existing Java_package_doSomething() function, forwarding all the arguments, and Bob's your uncle!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic