I have a java project using jdk11. I need to migrate the project to java 17 but integration tests have started failing. As soon as I upgraded to JDK17 I started getting below error:
java.lang.reflect.InaccessibleObjectException: Unable to make private sun.reflect.generics.repository.FieldRepository java.lang.reflect.Field.getGenericInfo() accessible: module java.base does not "opens java.lang.reflect" to unnamed module #5702b3b1
I was also getting error for java.util but that is fixed using below command line code.
I have tried adding the command line options as below but the tests are still failing
<argLine>
--illegal-access=permit
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/sun.reflect=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
</argLine>
Any help is appreciated.
You can pass your method in to this:
public static <T extends AccessibleObject> T forceAccessible(T o) {
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
Method m = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
m.setAccessible(true);
Field override = ((Field[]) m.invoke(AccessibleObject.class, false))[0];
if (!o.isAccessible()) {
try {
o.setAccessible(true);
} catch (InaccessibleObjectException e) {
unsafe.putBoolean(o, unsafe.objectFieldOffset(override), true);
}
}
} catch (Exception e) {}
return o;
}
Related
I've been trying to get a build archived for IOS by using Visual studio and the "Pair to mac" functionality.
However, when I try and do a release build, I get this error:
Error processing the method 'System.Void ProjectName.iOS.Renderers.IOSWebViewRenderer::.ctor()' in the assembly 'TextFlowMobile.iOS.exe': Object reference not set to an instance of an object TextFlowMobile.iOS
My code for this renderer, that is for WKWebView is as follows:
namespace TextFlowMobile.iOS.Renderers
{
public class IOSWebViewRenderer : WkWebViewRenderer
{
public override WKNavigation LoadHtmlString(NSString htmlString, NSUrl baseUrl)
{
try
{
if(htmlString != null && baseUrl != null)
{
// Add additional HTML to ensure fonts scale correctly and don't appear extremely small and almost unreadable
var iOSHtmlWithScaling = htmlString.ToString().Insert(0, "<meta name='viewport' content='width=device-width,initial-scale=1,maximum-scale=1' />");
return base.LoadHtmlString((NSString)iOSHtmlWithScaling, baseUrl);
}
else
{
return base.LoadHtmlString(htmlString, baseUrl);
}
}
catch (Exception)
{
//System.Diagnostics.Debug.WriteLine(ex);
return base.LoadHtmlString(htmlString, baseUrl);
}
}
}
}
As you can see, I don't override the constructor at all. I really don't see why this happens, especially since it builds (and deploys on a simulator on the connected mac) perfectly fine for debug.
My current config is Release | iPhone | ProjectName.iOS | Remote Device
I really appreciate any help!
This error occurred because I had an Obfuscator running on the release version of the code. When I tried to archive this, I imagine it couldn't properly compile this renderer because it was obfuscated.
I have the following routine that is the entry point for accessing serial ports in the usb4java API running in windows. Any ideas what can be wrong.
import javax.comm.*
public class SimpleJSComRead
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
if (portList.nextElement()==null) System.out.println("Is Null");
}
}
Concurrently, this works using jssc. I'm able to read valid data through this interface.
import jssc.SerialPort;
import jssc.SerialPortException;
public class SimpleJSComRead {
public static void main(String[] args) {
SerialPort serialPort = new SerialPort("COM6");
try { serialPort.openPort();
} catch (SerialPortException e) {
e.printStackTrace();
}
if (serialPort.isOpened()) System.out.println("opened successfully");
try { serialPort.closePort();
} catch (SerialPortException e) {
e.printStackTrace();
}
}
}
I tracked down the fact that the javax.comm library is not fully implemented or supported.
I find it strange that a basic function like reading from a serial port should be a difficult task for Java whereas hosting web applications is duplicated by various APIs. I expect serial communication is well supported in Python and C++ as these are more used by the scientific community.
The additional solution I found was to utilize RXTX API... one and two . The process involves downloading the zipped distribution and extracting the dlls and jars to some library site on your FileSystem. Then declare the dependency to the Jar file. For example in Gradle
compile files( 'C:/..path../lib/jars/RXTXcomm.jar').
and setting the dll library path and loading the dll
System.setProperty("java.library.path", "C:/..path../lib/dlls_x64")
System.loadLibrary("rxtxSerial")
Finally, the serial API is not in javax.comm package, but in the gnu.io package.
import gnu.io.CommPortIdentifier
import io.FileMgr
//this one is based on RXTX and dlls are in library (gnu.io)
fun main(args: Array<String>) {
FileMgr.setDllLibraryPath("C:/..path../lib/dlls_x64")
System.loadLibrary("rxtxSerial")
val portList = CommPortIdentifier.getPortIdentifiers()
while (portList.hasMoreElements()) {
val x = portList.nextElement() as CommPortIdentifier
println("Port Name = " + x.name + ", type= " + x.portType)
}
if (portList.nextElement() == null) println("Is Null")
}
fun setDllLibraryPath(resourceStr: String) {
try {
System.setProperty("java.library.path", resourceStr)
//System.setProperty("java.library.path", "/lib/x64");//for example
val fieldSysPath =
ClassLoader::class.java.getDeclaredField("sys_paths")
fieldSysPath.isAccessible = true
fieldSysPath.set(null, null)//next time path is accessed, the new path
will be imported
} catch (ex: Exception) {
ex.printStackTrace()
throw RuntimeException(ex)
}
}
when i fire a command ionic build android on terminal.
it show following error.
BUILD FAILED
Total time: 7.557 secs
Error: /Users/mac2/Desktop/myProj/platforms/android/gradlew: Command failed with exit code 1 Error output: /Users/mac2/Desktop/myProj/platforms/android/src/org/apache/cordova/firebase/FirebasePlugin.java:389: error: cannot find symbol
mFirebaseAnalytics.setCurrentScreen(cordova.getActivity(), name, null);
^
symbol: method setCurrentScreen(Activity,String,<null>)
location: variable mFirebaseAnalytics of type FirebaseAnalytics
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
below is the code in FirebasePlugin.java
private void setScreenName(final CallbackContext callbackContext, final String name) {
// This must be called on the main thread
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
try {
mFirebaseAnalytics.setCurrentScreen(cordova.getActivity(), name, null);
callbackContext.success();
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
}
I dont understand why such error occured in this file.
I try to solve, but i could not.
Can anyone have any idea why this happens?
Have a WPF app that I am converting to ASP.net and I am having issues with SAP.
When I run this line I get an exception.
RfcDestinationManager.RegisterDestinationConfiguration(Backend);
Exception Message {"exePath must be specified when not running inside a stand alone exe."}
Stack Trace
at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath, Boolean preLoad)
at System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel userLevel)
at SAP.Middleware.Connector.RfcConfigParameters..cctor()
googling around I saw as similar issue here exePath must be specified when not running inside a stand alone exe
The issue seems to be using ConfigurationManager.OpenExeConfiguration rather that System.Web.Configuration.WebConfigurationManagerwhich is what I need to use. Problem is I can't change that as its part of the SAP.Net Connector.
Is there anything I can do?
Edit: My BackendConfig code
public class BackendConfig : IDestinationConfiguration
{
public RfcConfigParameters GetParameters(String destinationName)
{
if ("P38".Equals(destinationName))
{
var parms = new RfcConfigParameters
{
{RfcConfigParameters.AppServerHost, "SAPSERVER"},
{RfcConfigParameters.SystemNumber, "86"},
{RfcConfigParameters.SncMode, "1"},
{RfcConfigParameters.SncPartnerName, "p:SAP#SERVER"},
{RfcConfigParameters.Client, "010"},
{RfcConfigParameters.Language, "EN"},
{RfcConfigParameters.PoolSize, "5"}
};
return parms;
}
else return null;
}
// The following two are not used in this example:
public bool ChangeEventsSupported()
{
return false;
}
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}
I'm trying to use nancy with JSON.net, follow the 2 ways that i found to register the dependencies but all way get me to an InvalidOperationException with a message "Something went wrong when trying to satisfy one of the dependencies during composition, make sure that you've registered all new dependencies in the container and inspect the innerexception for more details." with an inner exection of {"Unable to resolve type: Nancy.NancyEngine"}.
I'm using self hosting to run nancy and jeep everything really simple to been able just to test.
public static void Main(string[] args)
{
try
{
var host = new NancyHost(new Uri("http://localhost:8888/"));
host.Start(); // start hosting
Console.ReadKey();
host.Stop(); // stop hosting
}
catch
{
throw;
}
}
First I create a customSerializer
public class CustomJsonSerializer : JsonSerializer
{
public CustomJsonSerializer()
{
ContractResolver = new CamelCasePropertyNamesContractResolver();
Formatting = Formatting.Indented;
}
}
and then i tried 2 ways of registering
Using IRegistrations:
public class JsonRegistration : IRegistrations
{
public IEnumerable<TypeRegistration> TypeRegistrations
{
get
{
yield return new TypeRegistration(typeof(JsonSerializer), typeof(CustomJsonSerializer));
}
}
public IEnumerable<CollectionTypeRegistration> CollectionTypeRegistrations { get; protected set; }
public IEnumerable<InstanceRegistration> InstanceRegistrations { get; protected set; }
}
And also using Bootstrapper
public class NancyBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
container.Register<JsonSerializer, CustomJsonSerializer>();
}
}
Which means that when self hosting I add the custom bootstrapper
var host = new NancyHost(new Uri("http://localhost:8888/"), new NancyBootstrapper());
Both way return the same error.
Problem is actually the versions, the nancy json.net package is using Newton.Json 6.0.0.0, BUT when installing the package it will install automatically newer version that will create this problem. Not sure what has change in the Newton.JSON that will actually create this.
https://github.com/NancyFx/Nancy.Serialization.JsonNet/issues/27
Just to add my hard won knowledge in this area, after a greatly frustrating few hours using Nancy 1.4.1.
If you use a custom bootstrapper, make sure you make the call to base.ConfigureApplicationContainer(container); before you start your custom registrations.
So, not:
public class MyCustomBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
// MY BITS HERE...
base.ConfigureApplicationContainer(container);
}
}
but,
public class MyCustomBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container); // Must go first!!
// MY BITS HERE...
}
}
If you don't do this you will get the following error:
Something went wrong when trying to satisfy one of the dependencies
during composition, make sure that you've registered all new
dependencies in the container and inspect the innerexception for more
details.
with a helpful inner exception of:
Unable to resolve type: Nancy.NancyEngine
The solution of changing the order of these C# statements was actually alluded to in #StevenRobbins' excellent answer here (which I could have saved myself several hours of pain if I'd only read properly the first time).
Says Steven:
By calling "base" after you've made a manual registration you are
effectively copying over your original registration by autoregister.
Either don't call base, or call it before you do your manual
registrations.