Tag Archives: java

Record an error that the Tomcat resource publication cannot be updated:

Record an error that the Tomcat resource publication cannot be updated:

When it is found that Tomcat information is not updated after it is published, it is still the same as before; restart tomcat, delete the generated war package, and then re open it, it is found that there is no effect. After checking the configuration, it is found that there is no error. Check the resources under the published war package, and all the resources of the project are successfully published

So, after repeated operations, we finally found the error – the browser’s cache data is not cleared, delete the browser’s cache, restart, OK! No problem, Laotie

I hope my question will help you

Java retainAll throws an unsupported operation exception record

Today, when using Java’s retainAll method, I encountered an incredible problem. I reported a problem with JS bridge. But I’m sure that there is no problem with the JS bridge framework. I’ve been running for such a long time. So the problem lies in the use of the retainAll method of the final debug.

After the sentence “retain all”, although the page flashed back directly, there was no error in retain all. So I tried to try catch on the code to see what error was thrown. After debugging, I found that it was the error of unsupported operation exception. This means that the operation is not supported, that is, there is no such method?So I right-click the retainAll method and find that the comment of the retainAll method is as follows:

   /**
     * Retains only the elements in this list that are contained in the
     * specified collection (optional operation).  In other words, removes
     * from this list all of its elements that are not contained in the
     * specified collection.
     *
     * @param c collection containing elements to be retained in this list
     * @return <tt>true</tt> if this list changed as a result of the call
     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
     *         is not supported by this list
     * @throws ClassCastException if the class of an element of this list
     *         is incompatible with the specified collection
     * (<a href="Collection.html#optional-restrictions">optional</a>)
     * @throws NullPointerException if this list contains a null element and the
     *         specified collection does not permit null elements
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
     *         or if the specified collection is null
     * @see #remove(Object)
     * @see #contains(Object)
     */

Then I looked at the object of the array that I called retainAll, which is through the Arrays.asList This is the aslist method, as follows:

 @SafeVarargs
    @SuppressWarnings("varargs")
    public static <T> List<T> asList(T... a) {
        return new ArrayList<>(a);
    }

    /**
     * @serial include
     */
    private static class ArrayList<E> extends AbstractList<E>
        implements RandomAccess, java.io.Serializable
    {
        private static final long serialVersionUID = -2764017481108945198L;
        private final E[] a;

        ArrayList(E[] array) {
            a = Objects.requireNonNull(array);
        }

        @Override
        public int size() {
            return a.length;
        }

        @Override
        public Object[] toArray() {
            return a.clone();
        }

        @Override
        @SuppressWarnings("unchecked")
        public <T> T[] toArray(T[] a) {
            int size = size();
            if (a.length < size)
                return Arrays.copyOf(this.a, size,
                                     (Class<?extends T[]>) a.getClass());
            System.arraycopy(this.a, 0, a, 0, size);
            if (a.length > size)
                a[size] = null;
            return a;
        }

        @Override
        public E get(int index) {
            return a[index];
        }

        @Override
        public E set(int index, E element) {
            E oldValue = a[index];
            a[index] = element;
            return oldValue;
        }

        @Override
        public int indexOf(Object o) {
            E[] a = this.a;
            if (o == null) {
                for (int i = 0; i < a.length; i++)
                    if (a[i] == null)
                        return i;
            } else {
                for (int i = 0; i < a.length; i++)
                    if (o.equals(a[i]))
                        return i;
            }
            return -1;
        }

        @Override
        public boolean contains(Object o) {
            return indexOf(o) != -1;
        }

        @Override
        public Spliterator<E> spliterator() {
            return Spliterators.spliterator(a, Spliterator.ORDERED);
        }

        @Override
        public void forEach(Consumer<?super E> action) {
            Objects.requireNonNull(action);
            for (E e : a) {
                action.accept(e);
            }
        }

        @Override
        public void replaceAll(UnaryOperator<E> operator) {
            Objects.requireNonNull(operator);
            E[] a = this.a;
            for (int i = 0; i < a.length; i++) {
                a[i] = operator.apply(a[i]);
            }
        }

        @Override
        public void sort(Comparator<?super E> c) {
            Arrays.sort(a, c);
        }
    }

That is to say, the array object type generated by aslist is the internal class ArrayList. However, this class inherits the abstractlist and has no retainAll method. The retainAll method is java.util.List Methods in this class, ah Xi.. Solve the case.

So here, I think that I seem to have used the aslist method in other places. It seems that I need to check. After all, there are no add and remove methods.

mark!

Conclusion: This is a good question. It touches the blind area of knowledge and makes me more cautious. In the past, I used to use whatever method I could, but I didn’t really pay attention to the realization of the method. I didn’t know until I reported a mistake. It’s actually a bit fatal for programmers, because problems have already arisen. Therefore, we still need to read more source code and learn to recharge.

org.apache.jasper . jasperexception: unable to compile class for jsp: error resolution

1、 The main reason for this problem is that the version of servlet API does not match the version of Tomcat.

2、 Solutions.
I’m changing the version of Tomcat.
Put the plug-in code below into the pom.xml In the middle.

<!--<build>-->
    <!--<plugins>-->
      <!--<plugin>-->
        <!--<groupId>org.apache.tomcat.maven</groupId>-->
        <!--<artifactId>tomcat7-maven-plugin</artifactId>-->
        <!--<version>2.2</version>-->
        <!--<configuration>-->
          <!--<port>8888</port>-->
        <!--</configuration>-->
      <!--</plugin>-->
    <!--</plugins>-->
  <!--</build>-->

Start with tomcat7: run.

Start with tomcat7.
The problem can be solved.

Docker builds the pit that Seata stepped on. can not connect to services-server

An error is reported when the system starts: can not connect to services server.
Always connect to the intranet IP by default, but my configuration file specifies the extranet.

2020-07-29 14:53:39.075 ERROR 20356 --- [           main] i.s.c.r.netty.NettyClientChannelManager  : 0101 can not connect to 172.19.231.5:8091 cause:can not register RM,err:can not connect to services-server.
 
io.seata.common.exception.FrameworkException: can not register RM,err:can not connect to services-server.
	at io.seata.core.rpc.netty.NettyClientChannelManager.doConnect(NettyClientChannelManager.java:210) ~[seata-all-1.3.0.jar:1.3.0]
	at io.seata.core.rpc.netty.NettyClientChannelManager.acquireChannel(NettyClientChannelManager.java:103) ~[seata-all-1.3.0.jar:1.3.0]
	at io.seata.core.rpc.netty.NettyClientChannelManager.reconnect(NettyClientChannelManager.java:175) ~[seata-all-1.3.0.jar:1.3.0]

The configuration address of the mount directory is not easy to use, or it can’t be connected, and the error has been reported all the time

docker run -id --name seata-server -p 8091:8091 \
-v /java/seata/resources/file.conf:/seata-server/resources/file.conf \
-v /java/seata/resources/registry.conf:/seata-server/resources/registry.conf \
-v /java/seata/logs:/root/logs \
seataio/seata-server:1.3.0 /bin/bash

Finally, IP and final version should be specified at runtime to solve the problem

 docker run -id --name seata-server -p 8091:8091 \
> -e SEATA_IP=192.168.23.129 \
> -e SEATA_PORT=8091 \
> -v /java/seata/resources/file.conf:/seata-server/resources/file.conf \
> -v /java/seata/resources/registry.conf:/seata-server/resources/registry.conf \
> -v /java/seata/logs:/root/logs \
> seataio/seata-server:1.3.0

[Java] Java program error: exception_ ACCESS_ VIOLATION (0xc0000005)

When running Java program, error: exception_ ACCESS_ VIOLATION (0xc0000005);

According to the description of the original webpage:

EXCEPTION_ACCESS_VIOLATION

In rare circumstances, a Java program could stop with a message similar to the following:
 An unexpected error has been detected by HotSpot Virtual Machine:
 EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c042340, pid=1743, tid=122
 Java VM: Java HotSpot(TM) Client VM (1.5.4_02)
Problematic frame:
C [ntdll.dll+0x2430]
Essentially, Java will stop with a message such as the above if a "serious" error occurs that means the JVM can't continue to function. Usually, the most discriminating line is the first mention of a DLL, such as the line in bold above. The source of the error could be any of the following:

 1. a bug in the JVM itself; search Google and/or the Java web site for
    a mention of ntdll.dll+0x2430;
 2. a bug in some non-Java code that was being run at the time: e.g.
    Java might have been calling into a printer driver, graphics driver
    etc.

If you're not sure what to do but are not using the latest version of the JVM for your system, then a good first course of action is usually to upgrade your JVM. If the bug is in some other DLL, e.g. a printer driver, database driver, graphics driver etc, then it is best to see if you can upgrade the component in question.

If the error is occurring in some native code that you have written, then you need to find out which line of code corresponds to the offset mentioned (in this case, 0x2430, although the DLL isn't one of ours in this example). Usually you can tell your compiler to generate a "map 

The possible reasons are as follows:
1. A bug in the JVM itself; search Google and/or the Java Web site for
a mention of ntdll.dll +0x2430;
For a bug in the JVM itself, visit Google or the Java website (according to ntdll.dll +A bug in some non java code that was being run at the time: e.g.
java might have been calling into a printer driver, Graphics driver
etc.
a bug in a running non java code may cause the print driver to be called, such as the graphics driver;

Here, my suggestions are:
1. The port number may conflict, so close other unnecessary Java programs;
2 2. For the same Java program, some function may be set to start automatically (which will crowd out the Java program you are using). If there is a pause button, pause the function in the same Java program first (without affecting it), run the part of your own function first, and then start other functions after running this part of your own function;

Welcome to my official account:
[screen bridge community]

Spring security failed to log in, error: there is no passwordencoder mapped for the ID “null”

After writing the websecurityconfig class that inherits the websecurityconfigureradapter class, we need to define authentication in the configure (authentication manager builder auth) method, which is used to obtain information sources and password verification rules. (the name of the configure function doesn’t matter. The official name seems to be configureglobal (…) )It is important to configure the authenticationmanagerbuilder in the class annotated by @ enablewebsecurity or @ enableglobalmethodsecurity or @ enableglobalauthentication).

The source of authentication information I used at the beginning was in memory authentication. The code is as follows

 
    protected void configure (authentication manager auth) throws exception { // inmemoryauthentication gets from memory auth.inMemoryAuthentication ().withUser("user1").password("123456").roles("USER"); }

The login page of spring security is used. As a result, when logging in, the user name and password are correct, and the resource cannot be opened, so it still stays on the login page. There is no passwordencoder mapped for the ID "null".

Baidu found that this is because spring security 5.0 added a variety of encryption methods, but also changed the password format.

Let's take a look at the official documents. Here are the original words of the official documents:

 

-------------------------------------------------------------------------------------------------------------------

The general format for a password is:

{id}encodedPassword

Such that id is an identifier used to look up which PasswordEncoder should be used and encodedPassword is the original encoded password for the selected PasswordEncoder. The id must be at the beginning of the password, start with { and end with }. If the id cannot be found, the id will be null. For example, the following might be a list of passwords encoded using different id. All of the original passwords are "password".

{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG 
{noop}password 
{pbkdf2}5d923b44a6d129f3ddf3e3c8d29412723dcbde72445e8ef6bf3b508fbf17fa4ed4d6b99ca763d8dc 
{scrypt}$e0801$8bWJaSu2IKSn9Z9kM+TPXfOc/9bdYSrN1oD9qfVThWEwdRTnO7re7Ei+fUZRJ68k9lTyuTeUp4of4g24hHnazw==$OAOec05+bXxvuu/1qZ6NUR+xQYvYv7BeL1QxwRpY5Pc=  
{sha256}97cde38028ad898ebc02e690819fa220e88c62e0699403e94fff291cfffaf8410849f27605abcbc0

-------------------------------------------------------------------------------------------------------------------

 

The storage format of passwords in spring security is "{ID}.....". The front ID is the encryption method, the ID can be bcrypt, sha256, etc., followed by the encrypted password. In other words, when the program gets the passed password, it will first find the ID included by "{" and "}" to determine how the subsequent password is encrypted. If it cannot be found, it will be considered that the ID is null. This is why our program will report an error: there is no passwordencoder mapped for the ID "null". In the example of official documents, various encryption methods are used to encrypt the same password. The original password is "password".

 

If we want our project to log in normally, we need to modify the code in configure. We need to encrypt the password from the front end in some way. Spring security officially recommends using bcrypt encryption. So how to encrypt the password?Just specify it in the configure method.

After modification, it looks like this:

 
    protected void configure (authentication manager auth) throws exception { // inmemoryauthentication gets from memory auth.inMemoryAuthentication ().passwordEncoder(new BCryptPasswordEncoder()).withUser("user1").password(new BCryptPasswordEncoder().encode("123456")).roles("USER"); }

After inmemoryauthentication(), there is ". Passwordencoder (New bcryptpasswordencoder())", which is equivalent to using bcrypt encryption to process the user password when logging in. The previous ". Password (" 123456 ")" is changed to ". Password (New bcryptpasswordencoder(). Encode (" 123456 ")", which is equivalent to bcrypt encoding and encryption of the password in memory. The comparison is consistent, which indicates that the password is correct and login is allowed.

If you are also using the password from the memory, then according to the above modification should be successful login, no problem.

If you use to store the user name and password in the database, you usually use bcrypt code to encrypt the user password and store it in the database. And modify the configure() method, add ". Passwordencoder (New bcryptpasswordencoder())" to ensure that users use bcrypt to process the password when they log in, and then compare it with the password in the database. As follows:

 
    // inject the implementation class of userdetailsservice auth.userDetailsService (userService).passwordEncoder(new BCryptPasswordEncoder());
     

reprint https://blog.csdn.net/canon_ in_ d_ major/article/details/79675033

java.lang.IllegalStateException Exception: cause analysis and solution

Today, I write a java file download program. After it’s finished, everything is normal, but it always throws out java.lang.IllegalStateException Abnormal, although it does not affect the normal use, but it always makes people feel very uncomfortable. There is nothing wrong with checking the code. Finally, I checked a lot of information on the Internet and finally found out the reason.

When we upload or download files, or filter files, we may need to use the output stream of the page.
for example, when we use it in action:
for example, when we use it in action response.reset ();
     response.setContentType (”application/ vnd.ms -excel”);
    OutputStream os = response.getOutputStream ();
throw an exception: java.lang.IllegalStateException

Cause analysis:
this is a problem in the servlet code generated by the web container out.write (), which is invoked in JSP. response.getOutputStream () conflicts.
that is, the servlet specification states that it cannot be called either response.getOutputStream (), and then call response.getWriter (), no matter which one is called first, an IllegalStateException will be thrown when calling the second one,

Because in JSP, the out variable is generated through the response.getWriter It is used in the program response.getOutputStream , and the out variable is used, so the above error occurs.

solve:

Method 1: add the following two sentences to the JSP file

<%
out.clear ();
out = pageContext.pushBody ();
%>

Defects of this method:
many development projects are not caused by JSP front-end, such as freemaker, velocity and so on“ response.getOutputStream () “not in JSP, but in servlet/action

Method 2: in action, do not return to the specific result file, return null
instead

//return SUCCESS;
return null;

Java project cannot import entity class package and service package, controller layer reports error, fix project setup is OK

Frame SSH

The previous packages are all OK. I create a management class of the service layer. When I add a new service, it appears:

Java project cannot import entity class package and service package, controller layer reports an error,

At the beginning, I thought that the package was wrong. I deleted the package in the controller layer and imported it again, but it still couldn’t work,

Check the cause of the error and find out

Then select fix project setup and it will be OK.

Record down, in Baidu did not find the answer, follow-up continuous attention, have to know the reason can leave a message, thank you~~

When OFBiz project starts, caused by: org.codehaus.groovy . control.MultipleCompilationErrorsException : startup failed:

Error in console:

Caused by: org.ofbiz.base . util.GeneralException : Error loading Groovy script at [ component://zxdoc/webapp/zxdoc/WEB-INF/actions/index/PrepareBrowserInfo.groovy ]:  (startup failed:
component://zxdoc/webapp/zxdoc/WEB-INF/actions/index/PrepareBrowserInfo.groovy : 4: A transform used a generics containing ClassNode org.ofbiz.service . engine.GroovyBaseScript for the super class PrepareBrowserInfo directly. You are not supposed to do this. Please create a new ClassNode referring to the old ClassNode and use the new ClassNode instead of the old one. Otherwise the compiler will create wrong descriptors and a potential NullPointerException in TypeResolver in the OpenJDK. If this is not your own doing, please report this bug to the writer of the transform.

Translation: convert to include classnode org.ofbiz.service Generics of. Engine. Write groovybasescript directly for the superclass preparebrowserinfo. You shouldn’t do that. Create a new class node that references the old class node and use the new class node instead of the old class node. Otherwise, the compiler will create incorrect descriptors and potential nullpointerexceptions in openjdk’s typeresolver. If you did not do this yourself, report this error to the author of the transformation.
 @ line 4, column 1.
   UserAgent ua = UserAgent.parseUserAgentString ( request.getHeader (“User-Agent”));

Problems error:

Description    Resource    Path    Location    Type
Multiple Groovy compilers found on classpath. Continuing with compilation will produce unpredictible results. Remove a compiler before continuing.
Found 2.2 and 2.5    ofbiz-release14.12        ofbiz-release14.12    Groovy compiler mismatch problem

 

log4j:ERROR

I encountered this problem when writing Java log 4J log

I went to Baidu first. The possible reasons are as follows:

The jar package of 1 ﹣ log4j ﹣ is not correct

2. Install MyEclipse to disk C

3. The C disk of the computer is set with permission and cannot access the C: mylog.log PS: my problem

Then go to the log4j configuration file and modify the path

Change the path to disk d to solve the problem^-^

Thank you for your help~~~~~~