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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:07:32+00:00 2026-06-10T09:07:32+00:00

Is it 100% safe (exception / error free) to convert a byte[] that includes

  • 0

Is it 100% safe (exception / error free) to convert a byte[] that includes random binary data to a String via the constructor:

new String(bytes);
// -- or --
new String(bytes,"UTF-8");  // Or other charset

My concern is whether invalid UTF-8 bytes will cause an exception or other failure instead of just a possibly partially garbled message.

I have tried some known bad byte values, as they appear to work as expected. E.g:

byte[] bytes = new byte[] {'a','b','c',(byte)0xfe,(byte)0xfe,(byte)0xff,(byte)0xff,'d','e','f'};

String test = new String(bytes,"UTF-8");

System.out.println(test);

Prints “abc????def”.

My concern is if certain other combinations can fail in other unexpected ways since I cannot guarantee that I can test every invalid combination.

  • 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-10T09:07:33+00:00Added an answer on June 10, 2026 at 9:07 am

    This is covered in the docs:

    This method always replaces malformed-input and unmappable-character sequences with this charset’s default replacement string

    One thing that will fail, if you’re not always using UTF-8, is that it can throw UnsupportedEncodingException.

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

Sidebar

Related Questions

I'm wondering if editing remote files via ssh is 100% safe on public networks.
Now I do know that obfuscation is never 100% safe, but it's better than
I stumbled on a piece of Ajax code that is not 100% safe since
What is the best, safe and 100% free tool to be used on doing
100%I'm modifying an older website for a client that uses Ext-JS 1.1 and I'm
I have around 100 models, from MCMCglmm, that give output similar to this: >
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
Question is simple. How can I make 100% safe photo upload script with php?
I have a large activity that contains 100 or more buttons. But it's working
Is this code 100% safe from sql injection: $id = $_GET['id'] mysql_query('SELECT * FROM

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.