Error updating Java

3

A default notification appeared saying that there was a new Java update available, so I decided to upgrade. After the update I can not run my applications in Eclipse and the following message appears:

Imports:

ClassJoin

importandroid.app.Activity;importandroid.content.Intent;importandroid.graphics.Bitmap;importandroid.os.Bundle;importandroid.util.Log;importandroid.view.View;importandroid.widget.ImageView;importandroid.widget.Toast;

MainClass

importandroid.app.Activity;importandroid.content.Intent;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.TextView;

IwaslookingatthelibrariesinJavaBuildPathwhenIfoundthenativeAndroidlibrary(emptylibrary)andtheexternalannotations(Externalannotations).Isthisaproblem?

Libraries

Errormessageinlog Error in the log I had to put it in GitHub because it did not fit here

    
asked by anonymous 21.07.2018 / 21:52

2 answers

3

Somewhere in your project CadastroDeProdutos there should be this:

import sun.misc.BASE64Encoder;

For example, let's compile this class below:

import sun.misc.BASE64Encoder;
public class Teste {}

When doing this, the Java compiler up to version 8 immediately gives you a warning :

Teste.java:1: warning: BASE64Encoder is internal proprietary API and may be removed in a future release
import sun.misc.BASE64Encoder;
               ^

Translating:

  

BASE64Encoder is an internal proprietary API and can be removed in a future release

This warning should not be ignored. Classes beginning with sun. are internal to JDK and should not NEVER be used directly. For this reason, there is no guarantee as to their stability or availability. Any project that uses them runs the risk of not being portable.

In other words, in fact, your project has always been wrong from the beginning because it uses a class that should never have been used and compiled thanks to a language architecture failure.

The warning states that this class could be removed in a future version, and behold, one day that future version arrived! From Java 9, the proper mechanisms to hide classes that should not be visible were added as part of the modules concept. However, the sun.misc.BASE64Encoder class was not just hidden. It has in fact been completely removed from within JDK.

However, there is a simple solution to this problem. As of Java 8, the class java.util.Base64.Encoder was added. Therefore, there is no longer any use of sun.misc.BASE64Encoder . However, the APIs of the two classes have some differences, although there should be nothing too difficult to migrate.

It may even be that you are using an XPTO library from any third party and that this library is using sun.misc.BASE64Encoder . In this case the situation is a little more complicated, because there is the library that is wrong. This kind of situation created some fuss and a lot of people found it bad because of these unexpected failures. But then, we return to what the warning reports, that these classes should not be used directly, and therefore, it is the bad luck of who did it or trusted the library of someone who did it.

Moral of the story: Never use any class that starts with sun. . No wonder they have a very big warning saying they should not be used.

    
21.07.2018 / 23:09
3

This is not the answer I'd like to post, but come on:

First, I found more people reporting this bug or at least something very similar:

As I said in my other answer , the class sun.misc.BASE64Encoder was removed from Java 9 and in fact should never have been visible.

Eclipse uses a plugin called ADT, developed by Google, for Android development. In the depths of the ADT code, the sun.misc.BASE64Encoder class is used by a class named SignedJarBuilder which has a @Deprecated (fonte) .

However, the development of ADT was abandoned by Google in 2015 ( 1 and 2 ). The motivation was because ADT is full of bugs and security flaws and because Google wants to force everyone to migrate to Android Studio.

So the only existing solutions are all painful:

  • Running Eclipse in Java 8. Both Eclipse Oxygen and Eclipse Photon require Java 8 at least, so this should work. When you release some future version of Eclipse that has a minimum requirement of some Java ≥ 9, this will no longer be possible.

  • Migrate to Android Studio. Or maybe for Netbeans or something else.

  • Make an ADT fork and fix this and any other similar bugs that may arise. This is probably too hard to be worth.

22.07.2018 / 19:36