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 7414695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:09:07+00:00 2026-05-29T07:09:07+00:00

I found this little gem in our codebase at work recently. I have to

  • 0

I found this little gem in our codebase at work recently. I have to confess that I have absolutely no idea why this enum was written in this way (names changed to protect the innocent):

package foo.bar;

import sun.misc.SharedSecrets;
import foo.baz.HasAGetValuesMethod;

public enum MysteryEnum implements HasAGetValuesMethod {

   THINGY, BOB;

   @Override
   public MysteryEnum[] getValues() {
      return SharedSecrets.getJavaLangAccess().getEnumConstantsShared(MysteryEnum .class);
   }
}

In the getValues() method instead of simply calling MysteryEnum.values() it’s using something called sun.misc.SharedSecret to get a handle to something called sun.misc.JavaLangAccess, then using that to get an array of all the enum values. The Javadoc on that class tells you what the method does, but I can’t find much on why you would want to call it.

The developer that wrote this is no longer around, so I can’t ask him. I’m going to ask my team anyway, but I have a feeling that the answer will be: “Don’t know why it does that, but better not change it”. For the moment, I’m assuming that this is either an odd case of someone not knowing that the values() method exists, or that my ignorance of the sun.misc libraries is causing me to miss something obvious to others. Any idea’s why this code was written this way?

  • 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-29T07:09:07+00:00Added an answer on May 29, 2026 at 7:09 am

    The method returns the same array without reflection or copying/cloning the underlying array. This improves performance, but is not a good idea to exposes a mutable array.

    for (int i = 0; i < 3; i++)
        System.out.println(SharedSecrets.getJavaLangAccess().getEnumConstantsShared(AccessMode.class));
    AccessMode[] ams = SharedSecrets.getJavaLangAccess().getEnumConstantsShared(AccessMode.class);
    ams[1] = ams[2]; // don't do this !!
    System.out.println(EnumSet.allOf(AccessMode.class));
    

    prints

    [Ljava.nio.file.AccessMode;@330cdec1
    [Ljava.nio.file.AccessMode;@330cdec1
    [Ljava.nio.file.AccessMode;@330cdec1
    [READ, EXECUTE, EXECUTE]
    

    Instead of using this method, what I do is use my own cached copy

    // cannot be modified.
    private static final AccessMode[] ACCESS_MODES = AccessMode.values();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this little script in PHP that send a simple request to
So, I recently found this little gem. http://support.microsoft.com/kb/323308 Essentially, IE doesn't haven't Cache-Control: no-cache
I have two questions. 1) I found a little gem of code for how
I have this little piece of code that just checks for a particular text
I have this little program I write in ruby. I found a nice piece
I recently found this little piece of code for my .vimrc if has(autocmd) Highlight
I wanted to use groovy for a little ftp script and found this post
I've been struggling with this issue for a little while now. Found several posts
I found this open-source library that I want to use in my Java application.
i'm starting with Scala and i found this a little weird. In java i

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.