Proguard does not find basic packages and super class - proguard

I used to use proguard 5 on java 8, but as I now use Java 11, I've downloaded proguard 6.1.1, but I've encountered issues.
1 - Lot of warnings are generated because proguard does not find basic classes present in java.awt or java.lang:
Warning: ...: can't find referenced class java.awt.image.BufferedImage
Warning: ...: can't find referenced class javax.swing.JPanel
Warning: ...: can't find referenced class java.lang.management.ManagementFactory
I can remove all the warning by adding a global or specifics -dontwarn, but I don't think it's ideal. Is there a better solution?
2 - If I remove the warnings, with the option -dontwarn, an error is generated:
Unexpected error while performing partial evaluation:
Class = [...]
Method = [<init>()V]
Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [softwares/progeria/nuclei/NucleiLabeling] (with 1 known super classes) and [java/lang/InterruptedException] (with 4 known super classes))
Unexpected error while preverifying:
Class = [...]
Method = [<init>()V]
Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [...] (with 1 known super classes) and [java/lang/InterruptedException] (with 4 known super classes))
Error: Can't find common super class of [...] (with 1 known super classes) and [java/lang/InterruptedException] (with 4 known super classes)
The class that generates this error extends a JFrame and runs perfectly. How can I fix this error?

Your application depends on various runtime libraries which you need to tell ProGuard about.
Prior to Java 8, all of the built-in java libraries such as AWT, Swing etc. were bundled together in rt.jar. You would have supplied something like the following parameter to ProGuard:
-libraryjars <java.home>/lib/rt.jar
or if using Ant:
<libraryjar file="${java.home}/jre/lib/rt.jar" />
Since Java 9, these runtime libraries are packaged as a number of jmod files under <java.home>/jmods. As a minimum you will probably need:
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
or if using Ant:
<libraryjar file="${java.home}/jmods/java.base.jmod(!**.jar;!module-info.class)" />
However this will not include AWT or Swing, which are now in java.desktop.jmod. Precisely which of the jmods you need to link will depend on which Java runtime libraries your application makes use of.
In your case it looks like you need
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
-libraryjars <java.home>/jmods/java.destop.jmod(!**.jar;!module-info.class)
-libraryjars <java.home>/jmods/java.management.jmod(!**.jar;!module-info.class)
or
<libraryjar file="${java.home}/jmods/java.base.jmod" jarfilter="!**.jar" filter="!module-info.class" />
<libraryjar file="${java.home}/jmods/java.desktop.jmod" jarfilter="!**.jar" filter="!module-info.class" />
<libraryjar file="${java.home}/jmods/java.management.jmod" jarfilter="!**.jar" filter="!module-info.class" />
A web search for jmod <some class or package> or simply JDK Module Summary should help you identify any others you might need.
Note: If there is no <java.home>/jmods folder, and you use openjdk please note that there's a separate package for it search for java-11-openjdk-jmods to install the right package

Related

Javalin Migration from 3 to 4

We are migrating the Javalin from 3 to 4 in our current kotlin project. the dynamicGzip has been deprecated and replaced with compression strategy.
The pom.xml part will look like below.
<properties>
<javalin.version>4.1.1</javalin.version>
<jackson.version>2.13.0</jackson.version>
</properties>
The code part of kotlin is as follows
import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder.*
import io.javalin.http.BadRequestResponse
import io.javalin.http.NotFoundResponse
import io.javalin.http.staticfiles.Location
import io.javalin.plugin.json.JavalinJackson
import io.javalin.core.compression.*
val app = Javalin.create { config ->
config.defaultContentType = "application/json"
config.enableWebjars()
config.addStaticFiles("", Location.CLASSPATH)
config.enableCorsForAllgOrigins()
//it.dynamicGzip = true // deprecated method which was used in 3.12.0
config.compressionStrategy(Gzip(6))
}
We are using the migrating document from this link
https://javalin.io/migration-guide-javalin-3-to-4
When we try to build the project in intelij Idea with this change, ended with the below error.
D:\app\src\main\kotlin\app\app.kt:78:40
Kotlin: Unresolved reference: Gzip
What is that we are missing here?
Also it will be helpfull if config.addStaticFiles syntax is also added wrt javalin 4
Compression
The compressionStrategy method of the JavalinConfig class takes two parameters:
void compressionStrategy(Brotli brotli, Gzip gzip)
See the JavaDoc here.
The related classes are found in Javalin here:
import io.javalin.core.compression.Brotli;
import io.javalin.core.compression.Gzip;
So, you can do something like this in your set-up (my example is Java not Kotlin):
// my Java example:
config.compressionStrategy(new Brotli(6), new Gzip(6));
Static Files
You can use something like this (again, a Java example not Kotlin):
// my Java example:
config.addStaticFiles("/public", Location.CLASSPATH);
In this case, because I want my files to be on the runtime classpath, I have also created a public directory in my application's resources directory. Your specific implementation may differ.
You can also use Location.EXTERNAL if you prefer, to place the files somewhere else in your filesystem (outside the application).
Note also there is a small typo in config.enableCorsForAllgOrigins(). It should be:
config.enableCorsForAllOrigins()

Avro generated class: Cannot access class 'Builder'. Check your module classpath for missing or conflicting dependencies

Running
val myAvroObject = MyAvroObject.newBuilder()
results in a compilation error:
Cannot access class 'MyAvroObject.Builder'. Check your module classpath for missing or conflicting dependencies
I am able to access other MyAvroObject variables. More precisely, methods such as
val schema = MyAvroObject.getClassSchema()
val decoder = MyAvroObject.getDecoder()
compiles fine. What makes it even stranger is that I can access newBuilder() in my test/ folder, but not in my src/ folder.
Why do I get a compile error when using newBuilder()? Is the namespace of the avro-schema used to generate MyAvroObject of importance?
Check your module classpath generally means, that your dependencies (which you didn't provide) are messed up. One of them should read implementation instead of testImplementation, in order to have the method available in the main source-set, instead of only the test source-set - but this may well have to do with the input classes, the output location of generated classes, or annotations alike #VisibleForTesting (just see what it even generates). Command gradlew can also list the dependencies per configuration. The builder seems to be called org.apache.avro.SchemaBuilder... there's only avro-1.11.0.jar & avro-tools-1.11.0.jar. With the "builder" design pattern, .newBuilder() tries to return inner class Builder.
had the same problem today and was able to solve it by adding the following additional source folder
<sourceDir>${project.basedir}/target/generated-sources/avro</sourceDir>
to the kotlin-maven-plugin.

How to use a dependency of a module within a Play app

I am writing a Play Framework module in order to share some common logic among multiple Play apps. One of the things I would like my module to do is provide some frequently-used functionality by way of 3rd-party modules, for example the excellent Markdown module.
First of all, is it possible to do this? I want all the apps that include my module to be able to use the .markdown().raw() String extension without needing to explicitly declare the Markdown module as a dependency. The Play Framework Cookbook chapter 5 seems to imply that it is possible, unless I am reading it wrong.
Secondly, if it is possible, how does it work? I have created the following vanilla example case, but I'm still getting errors.
I created a new, empty application "myapp", and a new, empty module "mymod", both in the same parent directory. I then modified mymod/conf/dependencies.yml to:
self: mymod -> mymod 0.1
require:
- play
- play -> markdown [1.5,)
I ran play deps on mymod and it successfully downloaded and installed the Markdown module. Running play build-module also worked fine with no errors.
Then, I modified myapp/conf/dependencies.yml to:
# Application dependencies
require:
- play
- mymod -> mymod 0.1
repositories:
- Local Modules:
type: local
artifact: ${application.path}/../[module]
contains:
- mymod
I ran play deps on myapp and it successfully found mymod, and generated the myapp/modules/mymod file, containing the absolute path to mymod.
I ran myapp using play run and was able to see the welcome page on http://localhost:9000/. So far so good.
Next, I modified myapp/app/views/Application/index.html to:
#{extends 'main.html' /}
#{set title:'Home' /}
${"This is _MarkDown_, by [John Gruber](http://daringfireball.net/projects/markdown/).".markdown().raw()}
I restarted myapp, and now I get the following error.
09:03:23,425 ERROR ~
#6a6eppo46
Internal Server Error (500) for request GET /
Template execution error (In /app/views/Application/index.html around line 4)
Execution error occured in template /app/views/Application/index.html. Exception raised was MissingMethodException : No signature of method: java.lang.String.markdown() is applicable for argument types: () values: [].
play.exceptions.TemplateExecutionException: No signature of method: java.lang.String.markdown() is applicable for argument types: () values: []
at play.templates.BaseTemplate.throwException(BaseTemplate.java:86)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:257)
at play.templates.Template.render(Template.java:26)
at play.templates.GroovyTemplate.render(GroovyTemplate.java:187)
at play.mvc.results.RenderTemplate.<init>(RenderTemplate.java:24)
at play.mvc.Controller.renderTemplate(Controller.java:660)
at play.mvc.Controller.renderTemplate(Controller.java:640)
at play.mvc.Controller.render(Controller.java:695)
at controllers.Application.index(Application.java:13)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at Invocation.HTTP Request(Play!)
Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.String.markdown() is applicable for argument types: () values: []
at /app/views/Application/index.html.(line:4)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:232)
... 13 more
And just to confirm I'm not crazy, I tried adding the play -> markdown [1.5,) line to myapp/conf/dependencies.yml and restarted the app, and confirmed that it works.
I feel like I'm missing something obvious. Many thanks in advance to anyone who can help! :)
Yes I had the same problem, it seems that transitive dependencies through custom home made modules does not work

Grails Currencies Plugin: Unable to resolve class Money

I installed the grails currency plugin. I want to use the Money type in my grails domain class as such:
class FOO{
...
Money lunchCost = new Money(amount:0.00, currency:'USD')
Money dinnerCost = new Money(amount:0.00, currency:'USD')
...
}
I get an error when I compile saying "unable to resolve class Money". I traced the package heirchy of the Grails Money Plugin and tried to put in:
cr.co.arquetipos.currencies.Money breakfastCost = new cr.co.arquetipos.currencies.Money(amount:0.00, currency:'USD')
---- That didn't work either.
1) When I generated Foo, grails placed the domain class under "projectName.Foo" as it does for every domain class created.
2) I'm using Grails 1.3.5.
Do you have any ideas as to where the Currencies class is so I can include it in the
"import <....Money> and get rid of this compilation error?
Same here: The plugin does not integrate with the Grails project, at all. Nevertheless, it has been installed to ${user.home}/.grails/1.3.5/projects/${project.name}/plugins/currencies-0.3.
Since the plugin has been last updated in 2008 and doesn't cover too much functionality, I'd suggest to just copy the two domain classes (in the grails-app/domain folder) into your project.
For an evaluation, you may also want to have a brief look at grails-app/conf and test/integration in the plugin's installation folder.
Like ataylor says, don't use this plugin, it's broken. Instead use JScience. Checkout: Best practice to represent Money (value + currency) in Grails

Haskell compile dll

I need to create dll for this module
module MarketNews where
import Foreign
import Foreign.C.Types
import Foreign.C.String
import HighAPI(getNextNewsInfo)
getNextNewsInfoM :: IO CString
getNextNewsInfoM = getNextNewsInfo >>= \x -> newCString x
foreign export stdcall getNextNewsInfoM :: IO CString
I compiled :
C:\Users\test_8\Documents\Project\MarketNews\src>ghc --make MarketNews.hs -fglasgow
-exts
Also i have dllMain.o which created like http://haskell.org/ghc/docs/6.12.1/html/users_guide/win32-dlls.html and MyDef.def. After that i do next:
C:\Users\test_8\Documents\Project\MarketNews\src>ghc -shared -o MarketNews.dll M
arketNews.o MarketNews_stub.o dllMain.o MyDef.def
Creating library file: MarketNews.dll.a
Warning: resolving _getNextNewsInfoM by linking to _getNextNewsInfoM#0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
MarketNews.o:fake:(.text+0x6b): undefined reference to `HighAPI_getNextNewsInfo_
closure'
MarketNews.o:fake:(.text+0x12d): undefined reference to `__stginit_HighAPI_'
MarketNews.o:fake:(.data+0x10): undefined reference to `HighAPI_getNextNewsInfo_
closure'
collect2: ld returned 1 exit status
As i understand it faild because there must be a single root module. But why do i can use Foreign.* ? Why does i can not use HighAPI module ? Should i write whole programm in one file ?
Thanks.
GHC 6.12 supports creating a single DLL containing a Haskell library and all of its dependencies, including the RTS. It can't create separate DLLs of Haskell code that call each other, although that feature is implemented and may be available in the forthcoming GHC 6.14.1.
To answer your question, you need to also link in the HighAPI module when you create the DLL with ghc -shared. More information about creating Haskell DLLs is available in a blog post by Neil Mitchell (read this, because the information in the GHC user guide is wrong about a few things, in particular how to use DllMain).