Logging variable's javadoc - java

I'm using Crashlytics with my Android app. I'd like to log exceptions with descriptive messages.
One idea of mine is when starting an activity, if there is an error that results in the code finishing the activity is to set the result to "RESULT_ERROR" and then add data to the intent with an error code. In onActivityResult I'm logging an exception with
int error_code = data.getIntExtra(Const.KEY_ERROR_CODE, Const.ERROR_UNKNOWN);
Crashlytics.logException(new Exception(Integer.toString(error_code)));
I would like the string I'm logging to also contain a description of the error_code. I already describe the error code in the javadoc for the variable, so is there a way to retrieve the javadoc for a variable as a String?
Any suggestions? Thanks.

Related

I keep getting a permission error when trying to update a site's template in liferay 7.3

I've encountered an issue when trying to update a site's(group) template. The template is assigned and works correctly but a couple errors are thrown when doing so. They all read the same thing:
2023-01-18 10:42:24.934 ERROR [http-nio-8080-exec-48][FragmentRendererControllerImpl:120] Unable to render content of fragment entry 0:com.liferay.fragment.exception.FragmentEntryContentException: com.liferay.portal.kernel.portlet.PortletContainerException: java.lang.IllegalArgumentException: Someone may be trying to circumvent the permission checker: {company>
2023-01-18 10:42:24.936 ERROR [http-nio-8080-exec-48][FragmentRendererControllerImpl:120] Unable to render content of fragment entry 0:com.liferay.fragment.exception.FragmentEntryContentException: java.lang.NullPointerException
this is not an error i understand. As i'm not checking for permission, someone without permission simply wouldn't see the button and couldn't press it. I have code for that in my view.jsp, but even when i remove it the error still persist.
This is the code i have for updating a group:
// I first update a custom field showing if the site is active or not
group.getExpandoBridge().setAttribute("Status", "Actief" );
LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(groupId, true, true, privateTemp);
Like I said I tried removing any permission checking code but this had no effect. The method i'm using is from the LayoutSetLocalServiceUtil class. Given that it's a local this method shouldn't check for permission either. I'm also logged in as admin when I try to run my code so I should have the permission to do this anyway.
I also tried to hide the error using:
SessionMessages.add(portletRequest, PortalUtil.getPortletId(portletRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
But this didn't actually hide it for some reason and it doesn't solve the issue either. Did anyone encounter this before? And why do i keep getting a permission error without checking any permission?
I had similar permissions issues during the execution of custom code that updated ExpandoBridge attributes. Try the following update:
boolean isSecure = false; // Forces the use of ExpandoBridgeLocalService w/o permissions checking
// I first update a custom field showing if the site is active or not
group.getExpandoBridge().setAttribute("Status", "Actief", isSecure);
LayoutSetLocalServiceUtil.updateLayoutSetPrototypeLinkEnabled(groupId, true, true, privateTemp);
Reference:
https://docs.liferay.com/dxp/portal/7.4-latest/javadocs/portal-kernel/com/liferay/expando/kernel/model/ExpandoBridge.html#setAttribute-java.lang.String-java.io.Serializable-boolean-

Can log4j's error method print stack trace without string argument?

In regards to Log4j v2, I'd like to call log.error(exceptionTypeObj) and have the stack trace printed to my logfile instead of exceptionTypeObj.toString(). Is that possible?
I'd rather write code like log.error(e) and be done with it.
It's error prone and redundant for me to keep writing something like log.error("error", exceptionTypeObj).
The String parameter is redundant because you are not using it for the correct purpose. An Exception will tell you what error occurred but it won't tell you what you were trying to do when it happened. That is why you should always provide the string. Provide a String that says something like "Error occurred while attempting to update the user profile for user {}", and then provide the user name or id.
Without the String parameter you are forcing your support staff to call engineering to find out what the exception means and what they should do about it.

R.java strange error

I cannot figure out which kind of error is this.
We all saw a lot of strange stuff, regarding android and R.java, but I am seeing this for the first time.
In the R.java, i have the following line of code:
public static final class id {
public static final int 15dp=0x7f060067;
The error says - Syntax error on token "15d". delete this token.
At first I thought that I made some typo and wrote "15d" instead of "15dp" somewhere, but I didn't. I checked the entire layout xml file, that I was making the last, since after making it this error started appearing.
I tried deleting R.java and building the app, didn't helped.
Does anybody has a clue what this might be ?
You probably have in some layout file something like this:
android:id="+#id/15dp"
change this to a vaild id and try it again.
i know this question is already answered,but some more knowledge about this error:
R.java maintains all the references of id's of views,strings.xml tag names,Drawables etc, if you are facing this kind of issue,then it is necessarily the error of miss spell in some id naming,sting tag names or drawable name's something like this:
android:id="+#id/15dp"
dp is the unit for density independent pixel,so we can not assign this as id to any view neither as drawable name nor string tag name.
hope this helps.

Why the "The method getPreferenceOnScreen is depriciated" is shown?

I am developing a simple android app. I have set preferences through a method which is given below-
public void updateSummaries() {
getPreferenceScreen().findPreference(PREF_SIP_DOMAIN).setSummary(settings.getString(PREF_SIP_DOMAIN, DEFAULT_SIP_DOMAIN));
getPreferenceScreen().findPreference(PREF_SIP_PROXY).setSummary(settings.getString(PREF_SIP_PROXY, DEFAULT_SIP_PROXY));
getPreferenceScreen().findPreference(PREF_SIP_PROXY_PORT).setSummary(settings.getString(PREF_SIP_PROXY_PORT, DEFAULT_SIP_PROXY_PORT));
getPreferenceScreen().findPreference(PREF_STUN_UDP).setSummary(settings.getString(PREF_STUN_UDP, DEFAULT_STUN_UDP));
getPreferenceScreen().findPreference(PREF_STUN_UDP_PORT).setSummary(settings.getString(PREF_STUN_UDP_PORT, DEFAULT_STUN_UDP_PORT));
getPreferenceScreen().findPreference(PREF_STUN_TCP).setSummary(settings.getString(PREF_STUN_TCP, DEFAULT_STUN_TCP));
getPreferenceScreen().findPreference(PREF_STUN_TCP_PORT).setSummary(settings.getString(PREF_STUN_TCP_PORT, DEFAULT_STUN_TCP_PORT));
getPreferenceScreen().findPreference(PREF_TURN_UDP).setSummary(settings.getString(PREF_TURN_UDP, DEFAULT_TURN_UDP));
getPreferenceScreen().findPreference(PREF_TURN_UDP_PORT).setSummary(settings.getString(PREF_TURN_UDP_PORT, DEFAULT_TURN_UDP_PORT));
getPreferenceScreen().findPreference(PREF_TURN_TCP).setSummary(settings.getString(PREF_TURN_TCP, DEFAULT_TURN_TCP));
getPreferenceScreen().findPreference(PREF_TURN_TCP_PORT).setSummary(settings.getString(PREF_TURN_TCP_PORT, DEFAULT_TURN_TCP_PORT));
getPreferenceScreen().findPreference(PREF_TCP_MODE).setSummary(settings.getString(PREF_TCP_MODE, DEFAULT_TCP_MODE));
getPreferenceScreen().findPreference(PREF_AFE_MODE).setSummary(settings.getString(PREF_AFE_MODE, DEFAULT_AFE_MODE));
getPreferenceScreen().findPreference(PREF_BWM_MODE).setSummary(settings.getString(PREF_BWM_MODE, DEFAULT_BWM_MODE));
getPreferenceScreen().findPreference(PREF_HTTP_PROXY).setSummary(settings.getString(PREF_HTTP_PROXY, DEFAULT_HTTP_PROXY));
getPreferenceScreen().findPreference(PREF_HTTP_PROXY_PORT).setSummary(settings.getString(PREF_HTTP_PROXY_PORT, DEFAULT_HTTP_PROXY_PORT));
getPreferenceScreen().findPreference(PREF_HTTP_DOMAIN).setSummary(settings.getString(PREF_HTTP_DOMAIN, DEFAULT_HTTP_DOMAIN));
getPreferenceScreen().findPreference(PREF_TURN_USERNAME).setSummary(settings.getString(PREF_TURN_USERNAME, DEFAULT_TURN_USERNAME));
getPreferenceScreen().findPreference(PREF_TURN_PASSWORD).setSummary(settings.getString(PREF_TURN_PASSWORD, DEFAULT_TURN_PASSWORD));
getPreferenceScreen().findPreference(PREF_HTTP_PROXY_USERNAME).setSummary(settings.getString(PREF_HTTP_PROXY_USERNAME, DEFAULT_HTTP_PROXY_USERNAME));
getPreferenceScreen().findPreference(PREF_HTTP_PROXY_PASSWORD).setSummary(settings.getString(PREF_HTTP_PROXY_PASSWORD, DEFAULT_HTTP_PROXY_PASSWORD));
getPreferenceScreen().findPreference(PREF_TRANSPORT_MODE).setSummary(settings.getString(PREF_TRANSPORT_MODE, DEFAULT_TRANSPORT_MODE));
getPreferenceScreen().findPreference(PREF_AUTO_ANSWER).setSummary(settings.getString(PREF_AUTO_ANSWER, DEFAULT_AUTO_ANSWER));
}
But here the warning message is shown and sometimes I don't get any preferences set on the setting page. Can anyone say me that what is the root cause of this problem?
Somebody deprecated that method using the #Deprecated annotation, because they believe it should no longer be used.
You should find where that method is declared and read the documentation under #deprecated if provided, or find whoever manages that method in your organization to find out what alternatives they are suggesting.
Edit: My apologies, didn't realize this is an Android snippet. See android - getPreferenceScreen question made by another user.
They are suggesting that you should use getPreferenceManager() instead.
Like so:
getPreferenceManager().findPreference("keep").setEnabled(true);

How to retrieve tag value from quickfixj FIX.4.2 executionreport

I want to persist a fix4.2 message to database by retrieving the value of each tag. I am having the ExecutionReport object of the fix message.
I am retrieving the tag value of account using exec.getString(1) and this tag value is not present in the message so it is throwing FieldNotFound exception.
In Fiximate I found that account is not a mandatory field.
I also tried with exec.getAccount().getValue() but got same exception.
I found that every all these method throws FieldNotFound exception.
Is there any way to retrieve the tag value as null if that non-mandatory field is not present in the fix message.
Any help will be highly appreciated.
Thanks in advance.
Regards,
Shadab
You didn't say which QuickFIX port you are using (e.g. the original QF for C++, QF/J for Java, QF/n for C#).
If a field is not required, you simply need to test for its presence first.
C++: exec.isSetField(1) or exec.isSetField(field)
(there might also be a exec.isSetAccount(), not sure)
Java: exec.isSetField(1) or exec.isSetAccount() or exec.isSetField(field)
C#: exec.IsSet(1) or exec.IsSetAccount() or exec.IsSetField(field)

Categories

Resources