Try to find KotlinToJVMBytecodeCompiler.compileScript method in Kotlin 1.4.10 - kotlin

During migration my java project from Kotlin 1.2 to 1.4 I ran into a problem that there is no such method as KotlinToJVMBytecodeCompiler.compileScript() in v 1.4
Class<?> script = requireNonNull(KotlinToJVMBytecodeCompiler.INSTANCE.compileScript(environment, getClass().getClassLoader()), () -> file + " compilation failed");
Please suggest me what should I replace this with?
Thanks!

I was able to find this removal commit on github https://github.com/JetBrains/kotlin/commit/d863dc04e60ce82a162dbc4b5f1c9d379806177a#diff-36340d5f4473fd26b6fd3d39ac22b10560a53da22b65c763ba0b9e4d9864a18e
Then maybe you can see what you need to do to migrate your code to a new version, if not then maybe raise an issue on github that this public function has been removed without any info how to migrate to something new

Related

How can I parse info from kotlin docs to swagger-ui?

I need to parse kotlin docs (not swagger annotation) for swagger-ui.
I tried this, but it don't work.
Here my springdoc dependencies (springdocVersion = "1.6.6"). By the way, I can't use therapi version 0.13.0 if it's important.
runtimeOnly("org.springdoc:springdoc-openapi-kotlin:$springdocVersion")
implementation("org.springdoc:springdoc-openapi-ui:$springdocVersion")
implementation("org.springdoc:springdoc-openapi-webflux-ui:$springdocVersion")
implementation("org.springdoc:springdoc-openapi-javadoc:$springdocVersion")
annotationProcessor("com.github.therapi:therapi-runtime-javadoc-scribe:0.12.0")
implementation("com.github.therapi:therapi-runtime-javadoc:0.12.0")
After I replaced annotationProcessor("com.github.therapi:therapi-runtime-javadoc-scribe:0.12.0") with kapt("com.github.therapi:therapi-runtime-javadoc-scribe:0.12.0"), all worked well!
An example of the build file can be found here

Using sun.reflect package with openjdk11

Is there a way to use sun.reflect in OpenJDK11, by maybe adding something in "--add-exports"? Our code fails since a jide pkg internally uses sun.reflect package and I'm trying to see if there's a way to make it work.
I've already tried with the below but that doesn't help.
"--add-exports jdk.unsupported/sun.reflect=ALL-UNNAMED"
Here's the exception, where the underlying class references sun.reflect.Reflection
java.lang.NoClassDefFoundError: sun/reflect/Reflection
I had this problem and fixed it by using a newer version of jide. Changing from jide-whatever:3.2.3 to jide-whatever:3.7.6 was enough to make it work in my case.
If you cannot migrate to newer versions, the solution is to make a wrapper around Throwable().getStackTrace()[n].getClass() and put it in WEB-INF/classes folder
This is simple workaround. It works in many cases.
package sun.reflect;
public class Reflection {
public static Class<?> getCallerClass(int n){
StackTraceElement[] elements = new Throwable().getStackTrace();
return elements[n].getClass() ;
}
}
https://github.com/rafaljot/NoClassDefFoundError-sun-reflect-Reflection
It can be fixed when you update the version of the jars.

NullPointerException caught when writing to BigTable using Apache Beam's dataflow sdk

I'm using Apache's Beam sdk version 0.2.0-incubating-SNAPSHOT
and trying to pull data to a bigtable with the Dataflow runner. Unfortunately I'm getting NullPointerException when executing my dataflow pipeline where I'm using BigTableIO.Write as my sink. Already checked my BigtableOptions and the parameters are fine, according to my needs.
Basically, I create and in some point of my pipeline I have the step to write the PCollection<KV<ByteString, Iterable<Mutation>>> to my desired bigtable:
final BigtableOptions.Builder optionsBuilder =
new BigtableOptions.Builder().setProjectId(System.getProperty("PROJECT_ID"))
.setInstanceId(System.getProperty("BT_INSTANCE_ID"));
// do intermediary steps and create PCollection<KV<ByteString, Iterable<Mutation>>>
// to write to bigtable
// modifiedHits is a PCollection<KV<ByteString, Iterable<Mutation>>>
modifiedHits.apply("writting to big table", BigtableIO.write()
.withBigtableOptions(optionsBuilder).withTableId(System.getProperty("BT_TABLENAME")));
p.run();
When executing the pipeline, I got the NullPointerException, pointing out exactly to the BigtableIO class at the public void processElement(ProcessContext c) method:
(6e0ccd8407eed08b): java.lang.NullPointerException at org.apache.beam.sdk.io.gcp.bigtable.BigtableIO$Write$BigtableWriterFn.processElement(BigtableIO.java:532)
I checked this method is processing all elements before to write on bigtable, but not sure why I'm getting such exception overtime I execute this pipeline. According to the code below, this method uses bigtableWriter attribute to process each c.element(), but I can't even set a breakpoint to debug where is exactly the null. Any kind of advice or suggestion of how to solve this issue?
#ProcessElement
public void processElement(ProcessContext c) throws Exception {
checkForFailures();
Futures.addCallback(
bigtableWriter.writeRecord(c.element()), new WriteExceptionCallback(c.element()));
++recordsWritten;
}
Thanks.
I looked up the job and its classpath, and if I'm not mistaken it looks like you're using version 0.3.0-incubating-SNAPSHOT of beam-sdks-java-{core,io}, but version 0.2.0-incubating-SNAPSHOT of google-cloud-dataflow-java.
I believe the issue is because of this - you have to use the same version (more details: BigtableIO in version 0.3.0 uses #Setup and #Teardown methods, but runner 0.2.0 does not support them yet).

Mockolate Verify Error: Illegal override.. after Flex SDK 4.10 update

Since we upgraded the flex sdk in our application to 4.10 we've been running into Verify Errors while running unit tests that use mockolate.
They seem to occur when mocking an interface where a ByteArray is used in a method signature.
Example interface:
public interface IFileSystemHelper {
function loadFileContents(path:String):ByteArray;
}
Example test class:
public class SomeTest {
[Rule]
public var mockolateRule:MockolateRule = new MockolateRule();
[Mock]
public var fileHelper:IFileSystemHelper;
public function SomeTest() {
}
[Test]
public function testMethod():void {
// ...
}
}
When compiling and running the test with flexmojos 6.0.1 the following error is thrown:
VerifyError: Error #1053: Illegal override of
IFileSystemHelper8F2B5D281827800A824B85B588C6F2A08AE814ED in
mockolate.generated.IFileSystemHelper8F2B5D281827800A824B85B588C6F2A08AE814ED
My initial suspicion was an sdk version problem with playerglobal (or airglobal in our case) so i recompiled mockolate (and flexunit) with sdk 4.10, without any result.
The only thing that seems to work is to remove the ByteArray type from the method signature... but that's not really an option :-) (and this has never been a problem before)
Is there anyone who has had a similar issue?
Thanks
This problem usually occurs when compiling different parts of your application with different versions of the sdk.
I would recommend to have a look at the output of "mvn dependency:tree" as this should output all dependencies (direct and transitive ones). Perhaps this will help you find where the wrong version is comming from.

Using Apache Sling's Scala 2.8 Script Engine

I've been trying to use Apache Sling's Scala 2.8 Script Engine recently updated last month. I came from using Scala 2.7 along with Sling's Scala 2.7 Script Engine and that worked great. I run into a problem when I try to use the new implementation. When calling ScalaScriptEngine's eval function I always receive an "Error executing script" due to a NullPointerException. Has anyone else worked with the new build of the script engine and run into this as well?
Thanks!
Steven
There is a bug which prevent the Scala scripting engine from being used standalone. See https://issues.apache.org/jira/browse/SLING-1877 for details and a patch.
Also note, that with the patch applied you still need to set the class path when using the scripting engine. This is a change from 2.7.7 where the default java class path (i.e. java.class.path) was used automatically. In 2.8 you have to set this explicitly thorough the '-usejavacp' argument.
Here is some sample code demonstrating the standalone usage of the Scala scripting engine:
def testScalaScriptEngine() {
val scriptEngineFactory = new ScalaScriptEngineFactory
val settings = new ScalaSettings()
settings.parse("-usejavacp")
scriptEngineFactory.getSettingsProvider.setScalaSettings(settings)
val scriptEngine = scriptEngineFactory.getScriptEngine
val script = """
package script {
class Demo(args: DemoArgs) {
println("Hello")
}
}
"""
scriptEngine.getContext.setAttribute("scala.script.class", "script.Demo", ScriptContext.ENGINE_SCOPE)
scriptEngine.eval(script)
}