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

  • SEARCH
  • Home
  • 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 8999415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:10:38+00:00 2026-06-16T00:10:38+00:00

I’d like to be able to generate and load custom classes within an (unsigned)

  • 0

I’d like to be able to generate and load custom classes within an (unsigned) applet. Generating them I can deal with, but I’m battling with the applet SecurityManager that doesn’t seem to want me to load them.

Here’s a visual overview; as you can see I’m stuck on Phase 2:

underpants gnomes

What I originally intended was to use a custom class loader. Apparently this isn’t allowed in an applet; the ClassLoader constructor throws a SecurityException.

Then I considered calling ClassLoader.defineClass(String name, byte[] b, int off, int len) on another class loader directly, but that method is protected.

I tried to make the method accessible via reflection. My hopes there weren’t high but I tried it and indeed that too threw a SecurityException.

URLClassLoader appeared to offer salvation: it has a static factory creation method which does not throw any security exception. However, that technique doesn’t permit subclassing the loader or access to the protected defineClass method. It only accepts an array of URL objects.

So I tried to subclass URL to override its openConnection method to return my class bytes that way, but the URL class is final.

Then I tried creating a custom URLStreamHandler with an overridden openConnection method and passing it to the constructor of a URL. The SecurityManager threw another fit over this.

So then I tried calling URL.setStreamHandlerFactory with a custom factory that would return my custom stream handler. There was the SecurityManager again, complaining, because what else is it good for if not complaining?

So then I tried creating a javax.management.loading.MLet. I have no clue what it’s for but it’s a subclass of URLClassLoader that allows specifying a custom URLStreamHandlerFactory in its constructor and doesn’t mention throwing a security exception, but it still did anyway.

In desperation I tried calling ProxySelector.setDefault with a custom ProxySelector, hoping to incercept a URL and somehow route it back into my applet, but I don’t have permission for that either.

I tried setting the java.system.class.loader property via a <param name="java_arguments" ...> tag, but it didn’t seem to be one of the honored properties.

Finally, the only remaining way I can think of to do this is to send my class bytes up to a remote server that will generate a temporary URL that I can use in conjunction with URLClassLoader.newInstance(URL[]). That would work but I really don’t like the idea. It seems like it could get complicated fast, with the interaction of the different ClassLoaders, and the server-dependence is not really practical for what I want to do. Apparently the SecurityManager is only too happy to let you create a URLClassLoader, but gets spontaneously upset when you try to use it.

I would like to do this from within the normal unsigned applet security sandbox if it’s at all possible, so that the experience is seamless.

But mostly I’m just baffled, because if it’s not possible it makes no sense. If the SecurityManager is happy about loading classes from arbitrary external URLs it shouldn’t mind loading one from a byte array in a local variable. The restriction is still nonsensical. The code is still internal and sandboxed.

It’s useful both for dynamic code generation and for implementing custom JAR compression, like LZMA compression.

Help!

  • 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-06-16T00:10:39+00:00Added an answer on June 16, 2026 at 12:10 am

    ..the SecurityManager again, complaining, because what else is it good for if not complaining?

    It is there for the protection of the end user, against doing exactly the sorts of things you are attempting.

    ..how do I load the class?

    Sign the Jar, get the user to accept the digitally signed code.

    ..send my class bytes up to a remote server that will generate a temporary URL that I can use in conjunction with URLClassLoader.newInstance(URL[]).

    A sand-boxed applet cannot create an URLClassLoader.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms

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.