ProGuard difficulties when obfuscating with libraries - java

While trying to use ProGuard (4.9) to obfuscate and optimise a desktop application everything works up until I use something from an external library such as JSoup.connect("http://google.com/").get();. I would get the following error:
Exception in thread "Thread-2" java.lang.ExceptionInInitializerError
at org.jsoup.b.l.<clinit>(Unknown Source)
at org.jsoup.b.f.<init>(Unknown Source)
at org.jsoup.b.e.<init>(Unknown Source)
at org.jsoup.c.bh.b(Unknown Source)
at org.jsoup.c.bh.a(Unknown Source)
at org.jsoup.c.b.a(Unknown Source)
at org.jsoup.c.D.a(Unknown Source)
at org.jsoup.a.a.a(Unknown Source)
at org.jsoup.a.i.e(Unknown Source)
at org.jsoup.a.e.a(Unknown Source)
at package.a.a(Unknown Source)
at package.a.b(Unknown Source)
at package.w.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at org.jsoup.b.k.d(Unknown Source)
at org.jsoup.b.k.<clinit>(Unknown Source)
... 14 more
I have tried searching for a solution but the answer would always be for an android application. With no luck I have attempted the following:
Turn off Use mixed-class names
Added to config -keep public enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
Recently, going through with this process using ProGuard 5.2, not much has changed. Here is the updated process to fixing the issue:
Go to the Obfuscation tab.
Go to the bottom for Keep additional class names and class member names
Click on Add... to the right
Go down to Extends/implements class and type in your library matching the examples below then press Ok. Repeat for every library.
For JSoup: org.jsoup.**
For Apache Commons Net: org.apache.commons.net.**
For SwingX: org.jdesktop.**
For GSON: org.google.gson.**
Go to the Information tab.
Turn off Skip non-public library class members
Turn on Ignore warnings about possibly erroneous input
Process!

Related

PowerMock : After Adding a particular class in #PrepareForTest, getting 'Invalid this class index 11012 in constant pool' error

#PrepareForTest({ A.class, B.class, SomeJavaClass.class, D.class})
class ReportActionTest
{
// JUnit class having around 10,000 lines of code
}
class SomeJavaClass
{
//Java class having around 10,500 lines of code
}
All JUnits of ReportActionTest were executing properly until I added few new methods in SomeJavaClass.
After Adding new methods, I tried to run JUnits of ReportActionTest.
But ReportActionTest couldn't load.
Following is the error log :
java.lang.ClassFormatError: Invalid this class index 11012 in constant pool in class file com/app/reports/web/action/SomeJavaClass
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:210)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:145)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at junit.framework.TestSuite.getTestConstructor(TestSuite.java:83)
at org.powermock.modules.junit3.internal.impl.PowerMockJUnit3RunnerDelegateImpl.<init>(PowerMockJUnit3RunnerDelegateImpl.java:54)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit3TestSuiteChunkerImpl.java:75)
at org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit3TestSuiteChunkerImpl.java:37)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:217)
at org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl.<init>(JUnit3TestSuiteChunkerImpl.java:46)
... 20 more
Then I Removed some of the old methods(not newly added ones) of SomeJavaClass.class(Just to reduce it's size).
Then I tried to run JUnits of ReportActionTest and ReportActionTest loaded properly.
So, I wanted to know, is there any limitation on size of the classes added in #PrepareForTest ?
I want to understand this behaviour, if anyone can explain.

SOAP web service not working for EJB calls

I am trying to create a SOAP based web service, which will call stateless EJB in other project. My configuration is Server: WAS 8.5,IDE: RAD 8.5,Java 1.6, EJB 3.1, and SOAP 1.1. When I write a simple addition method it properly create Web Service, WSDL and i can access the Web Service. But When i add another method which calls EJB it wont allows me to create service and WSDL, it throws below error popup :
Errors occurred during wsgen.
error: compilation failed, errors should have been reported
warning: The apt tool and its associated API are planned to be
removed in the next major JDK release. These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model. Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.
Note: ap round: 1
Problem encountered during annotation processing;
see stacktrace below for more information.
java.lang.NullPointerException
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalType(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalMethod(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.methodsAreLegal(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.isLegalImplementation(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.shouldProcessWebService(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceVisitor.visitClassDeclaration(Unknown Source)
at com.sun.tools.apt.mirror.declaration.ClassDeclarationImpl.accept(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceAP.buildModel(Unknown Source)
at com.ibm.jtc.jax.tools.ws.processor.modeler.annotation.WebServiceAP.process(Unknown Source)
at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(Unknown Source)
at com.sun.tools.apt.comp.Apt.main(Unknown Source)
at com.sun.tools.apt.main.AptJavaCompiler.compile(Unknown Source)
at com.sun.tools.apt.main.Main.compile(Unknown Source)
at com.sun.tools.apt.main.Main.compile(Unknown Source)
at com.sun.tools.apt.Main.processing(Unknown Source)
at com.sun.tools.apt.Main.process(Unknown Source)
at com.sun.tools.apt.Main.process(Unknown Source)
at com.ibm.jtc.jax.tools.ws.wscompile.WsgenTool.buildModel(Unknown Source)
at com.ibm.jtc.jax.tools.ws.wscompile.WsgenTool.run(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.ibm.ast.ws.jaxws.emitter.jws22.v85.command.AbstractWsGenCommand.execute(Unknown Source)
at com.ibm.ast.ws.jaxws.emitter.command.WsGenCommand.execute(Unknown Source)
....
This is my code which works fine
public class Operations {
public int addition(int x, int y){
return x+y;
}
public String Greetings(String name){
return "happy birthday"+name;
}
}
when i add
#EJB
private transient StatusEJBBeanLocal statusEJBBeanLocal;
public Product StatusFromProductId(int ProdutoID) {
Product produto = null;
produto = this.statusEJBBeanLocal.StatusFromProductId(ProdutoID);
return produto;
}
It shows error. Please help me out here with some tutorial link or tell me whats wrong with my code, how to call EJB from Web services. Thanks in advance.

Exception in "JavaFX Application Thread" when using JavaFX control

I am initializing a generic JavaFX 8 ComboBox with Enum values as follows:
ObservableList<MyEnumClass> myValues = FXCollections
.observableArrayList(MyEnumClass.FIRST_ENUM,
MyEnumClass.SECOND_ENUM, MyEnumClass.THIRD_ENUM);
myEnumComboBox = new ComboBox<MyEnumClass>(myValues);
A test application shows the ComboBox with the Enum values as expected and selecting other values also works fine. But one thing puzzels me: Even though I can not observe any apparent malfunction, my Eclipse console nevertheless notifies me about an exception in thread "JavaFX Application Thread" whenever I select a new value from the ComboBox's menu. The exception seems to be related to the native JavaFX code that hides the ComboBox's popup control:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: null source
at java.util.EventObject.<init>(Unknown Source)
at java.awt.AWTEvent.<init>(Unknown Source)
at sun.awt.UngrabEvent.<init>(Unknown Source)
at javafx.embed.swing.SwingNode$10.handle(Unknown Source)
[9 lines omitted]
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at com.sun.javafx.stage.WindowPeerListener.focusUngrab(Unknown Source)
[4 lines omitted]
at com.sun.glass.ui.Window.handleWindowEvent(Unknown Source)
at com.sun.glass.ui.Window.notifyFocusUngrab(Unknown Source)
at com.sun.glass.ui.win.WinWindow._ungrabFocus(Native Method)
at com.sun.glass.ui.Window.ungrabFocus(Unknown Source)
at com.sun.javafx.tk.quantum.WindowStage.ungrabFocus(Unknown Source)
at javafx.stage.Window.decreaseFocusGrabCounter(Unknown Source)
at javafx.stage.PopupWindow.handleAutohideActivation(Unknown Source)
at javafx.stage.PopupWindow.impl_visibleChanged(Unknown Source)
at javafx.stage.Window$9.invalidated(Unknown Source)
at javafx.beans.property.BooleanPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.BooleanPropertyBase.set(Unknown Source)
at javafx.stage.Window.setShowing(Unknown Source)
at javafx.stage.Window.hide(Unknown Source)
at javafx.stage.PopupWindow.hide(Unknown Source)
at com.sun.javafx.scene.control.skin.ComboBoxPopupControl.hide(Unknown Source)
[44 lines omitted]
at java.lang.Thread.run(Unknown Source)
Can somebody explain what exactly is happening here and what I can or should do about it?
EDIT - The exception was caused by a leftover SwingNode from some earlier experiment on the same Pane as the ComboBox. Deleting the SwingNode made the exception vanish.

Skype error? Or Eclipse error?

I tried making a simple project for my skype-bot, and it looks like this:
import com.skype.Skype;
import com.skype.SkypeException;
public class SkypeDemo {
public static void main(String[] args) throws SkypeException {
System.out.println(Skype.getVersion());
}
}
But when i started it i get this error:
Exception in thread "main" com.skype.SkypeException: Loading libskype.jnilib failed.
at com.skype.Utils.convertToSkypeException(Unknown Source)
at com.skype.Utils.getProperty(Unknown Source)
at com.skype.Skype.getVersion(Unknown Source)
at SkypeDemo.main(SkypeDemo.java:6)
Caused by: com.skype.connector.LoadLibraryException: Loading libskype.jnilib failed.
at com.skype.connector.ConnectorUtils.loadLibrary(Unknown Source)
at com.skype.connector.osx.SkypeFramework.init(Unknown Source)
at com.skype.connector.osx.OSXConnector.initializeImpl(Unknown Source)
at com.skype.connector.Connector.initialize(Unknown Source)
at com.skype.connector.Connector.connect(Unknown Source)
at com.skype.connector.Connector.assureAttached(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
at com.skype.connector.Connector.execute(Unknown Source)
... 3 more
So how do I fix this error? Keep in mind I have both Skype jars in the build path.
The error is telling you that it cannot load a native library ("libskype.jnilib"). This is (probably) neither Eclipse or Skype's fault.
It is most likely your fault because either the native library is not where it needs to be (or you haven't told Eclipse where to look), or because you have the wrong flavour of native code (DLL, .so or whatever)
(If there was another chained "cause" in the stack trace, it might tell you more ...)
Reference:
This blog post explains how to add a native library to an Eclipse project - http://www.eclipsezone.com/eclipse/forums/t49342.html (In fact, it describes two ways ...)

Java Game - ClassCastException

I am developing a simple java game and my scrollbar is raising an exception.
The scrollbar is supposed to be a "gameslider".
Exception in thread "Thread-3" java.lang.ClassCastException: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.d3d.D3DSurfaceData
at sun.java2d.d3d.D3DRenderer.copyArea(Unknown Source)
at sun.java2d.d3d.D3DSurfaceData.copyArea(Unknown Source)
at sun.java2d.SunGraphics2D.doCopyArea(Unknown Source)
at sun.java2d.SunGraphics2D.copyArea(Unknown Source)
at javax.swing.BufferStrategyPaintManager.copyArea(Unknown Source)
at javax.swing.RepaintManager.copyArea(Unknown Source)
at javax.swing.JViewport.blitDoubleBuffered(Unknown Source)
at javax.swing.JViewport.windowBlitPaint(Unknown Source)
at javax.swing.JViewport.setViewPosition(Unknown Source)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.hsbStateChanged(Unknown Source)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.fireStateChanged(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.setRangeProperties(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.setValue(Unknown Source)
at javax.swing.JScrollBar.setValue(Unknown Source)
at GameEnvironment.GamePanel.gameUpdate(GamePanel.java:171)
at GameEnvironment.GamePanel.run(GamePanel.java:73)
at java.lang.Thread.run(Unknown Source)
Code Line is following:
if (reachedMiddle)
scrollPane.getHorizontalScrollBar().setValue(player.getX() - (widthHorizontalScrollBar / 2));
The exception will be raised more or less randomly. I didnt figured it out so far.
I would make sure this code is run on the GUI Event Thread. If you call the Swing components on other threads you can get strange, randonm errors.
Have a look at using SwingUtilities.invokeLater(Runnable) to perform the tasks where the Swing components are updated.

Categories

Resources